From 2adcf8f0777932358794d0b625932d6f90728bb5 Mon Sep 17 00:00:00 2001 From: cheney Date: Fri, 7 Aug 2026 11:33:57 +0800 Subject: [PATCH] Changes to be committed: modified: src/App.tsx new file: src/__tests__/utils/extract-cert.test.ts new file: src/utils/extract-cert.js modified: src/version.js --- src/App.tsx | 116 +++++++++- src/__tests__/utils/extract-cert.test.ts | 23 ++ src/utils/extract-cert.js | 281 +++++++++++++++++++++++ src/version.js | 2 +- 4 files changed, 420 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/utils/extract-cert.test.ts create mode 100644 src/utils/extract-cert.js diff --git a/src/App.tsx b/src/App.tsx index a67e343..e53906b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import { sm2GenerateKeyPair, sm2GetPublicKeyFromPrivateKey, sm2Encrypt, sm2Decry import { parseSm2Cert, parseCertFromFile, generateRootCert, generateAppCert, generateCrlFile, loadRootPrivateKeyFromCache } from './utils/algorithm/cert' import { hexToUtf8, utf8ToHex, hexToBase64, base64ToHex } from './utils/convert' import { getInfoFromPKCS7, verifyPKCS7 } from './utils/crypto.js' +import { extractCertificate, extractCertificateFromText } from './utils/extract-cert.js' function App() { // 从localStorage读取当前分类,默认sm3 @@ -189,6 +190,9 @@ function App() { const [pkcs7Info, setPkcs7Info] = useState(null) const [originalData, setOriginalData] = useState('') const [verifyResult, setVerifyResult] = useState('') + const [extractInput, setExtractInput] = useState('') + const [extractedCert, setExtractedCert] = useState(null) + const [extractError, setExtractError] = useState('') @@ -410,6 +414,36 @@ function App() { } } + const handleExtractCertificate = () => { + try { + const result = extractCertificate(extractInput) + setExtractedCert(result) + setExtractError('') + } catch (error) { + setExtractError((error as Error).message) + setExtractedCert(null) + } + } + + const handleDownloadExtractedCert = (type: 'der' | 'pem') => { + if (!extractedCert) { + setExtractError('请先提取证书') + return + } + + const content = type === 'der' ? extractedCert.der : extractedCert.pem + const blob = new Blob([content], { type: type === 'der' ? 'application/octet-stream' : 'application/x-pem-file' }) + const downloadUrl = URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = downloadUrl + link.download = type === 'der' ? 'extracted-cert.der' : 'extracted-cert.pem' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + URL.revokeObjectURL(downloadUrl) + setExtractError('') + } + // 处理 PKCS7 签名信息提取 const handleGetInfoFromPKCS7 = () => { try { @@ -1899,9 +1933,89 @@ function App() { + {/* 提取证书 */} +
+

4. 提取证书

+
+ +