diff --git a/package-lock.json b/package-lock.json index dd47761..7747596 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "gmsm-sm2js": "^0.7.1", "gmsm-sm3js": "^0.2.0", "gmsm-sm4js": "^0.7.0", + "jsrsasign": "^11.1.3", "node-forge": "^1.4.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/package.json b/package.json index 1d8b953..dddb50f 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "gmsm-sm2js": "^0.7.1", "gmsm-sm3js": "^0.2.0", "gmsm-sm4js": "^0.7.0", + "jsrsasign": "^11.1.3", "node-forge": "^1.4.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/src/App.tsx b/src/App.tsx index 27b989c..bd53de4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { sm4Encrypt, sm4Decrypt } from './utils/algorithm/sm4' import { sm2GenerateKeyPair, sm2GetPublicKeyFromPrivateKey, sm2Encrypt, sm2Decrypt, sm2Sign, sm2Verify } from './utils/algorithm/sm2' import { parseSm2Cert, parseCertFromFile, generateRootCert, generateAppCert } from './utils/algorithm/cert' import { hexToUtf8, utf8ToHex, hexToBase64, base64ToHex } from './utils/convert' +import { getInfoFromPKCS7, verifyPKCS7 } from './utils/crypto.js' function App() { // 从localStorage读取当前分类,默认sm3 @@ -179,6 +180,12 @@ function App() { const [appCert, setAppCert] = useState('') const [commonName, setCommonName] = useState('test.example.com') const [certError, setCertError] = useState('') + + // PKCS7 签名工具状态 + const [pkcs7Signature, setPkcs7Signature] = useState('') + const [pkcs7Info, setPkcs7Info] = useState(null) + const [originalData, setOriginalData] = useState('') + const [verifyResult, setVerifyResult] = useState('') @@ -318,6 +325,30 @@ function App() { } } + // 处理 PKCS7 签名信息提取 + const handleGetInfoFromPKCS7 = () => { + try { + const info = getInfoFromPKCS7(pkcs7Signature) + setPkcs7Info(info) + setCertError('') + } catch (error) { + setCertError((error as Error).message) + setPkcs7Info(null) + } + } + + // 处理 PKCS7 签名验证 + const handleVerifyPKCS7 = () => { + try { + const result = verifyPKCS7(pkcs7Signature, originalData) + setVerifyResult(result ? '验证成功' : '验证失败') + setCertError('') + } catch (error) { + setCertError((error as Error).message) + setVerifyResult('') + } + } + // SM2 生成密钥对 const handleGenerateSm2KeyPair = () => { try { @@ -1703,6 +1734,155 @@ function App() { )} + + {/* PKCS7 签名工具 */} +
+

4. PKCS7 签名工具

+ +
+ +