From 4b3d5b762fb9010f4fd82a4384fae98d0464029a Mon Sep 17 00:00:00 2001 From: cheney Date: Tue, 28 Apr 2026 11:18:22 +0800 Subject: [PATCH] hotfox --- src/App.tsx | 123 ++++++++++++++++++++++++++++++++++++- src/utils/algorithm/sm2.ts | 18 +++--- src/version.js | 2 +- 3 files changed, 132 insertions(+), 11 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 27b989c..d7875b8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,7 +3,7 @@ import { VERSION } from './version' import { sm3Digest, sm3Hmac } from './utils/algorithm/sm3' import { sm4Encrypt, sm4Decrypt } from './utils/algorithm/sm4' -import { sm2GenerateKeyPair, sm2GetPublicKeyFromPrivateKey, sm2Encrypt, sm2Decrypt, sm2Sign, sm2Verify } from './utils/algorithm/sm2' +import { sm2GenerateKeyPair, sm2GetPublicKeyFromPrivateKey, sm2Encrypt, sm2Decrypt, sm2Sign, sm2Verify, sm2DerToC1C3C2, sm2C1C3C2ToDer } from './utils/algorithm/sm2' import { parseSm2Cert, parseCertFromFile, generateRootCert, generateAppCert } from './utils/algorithm/cert' import { hexToUtf8, utf8ToHex, hexToBase64, base64ToHex } from './utils/convert' @@ -172,6 +172,8 @@ function App() { const [hexInput, setHexInput] = useState('') const [utf8Input, setUtf8Input] = useState('') const [base64Input, setBase64Input] = useState('') + const [derInput, setDerInput] = useState('') + const [c1c3c2Input, setC1c3c2Input] = useState('') // 证书工具状态 const [certInfo, setCertInfo] = useState(null) @@ -262,6 +264,26 @@ function App() { } } + // DER 转 C1C3C2 + const handleDerToC1C3C2 = () => { + try { + const c1c3c2 = sm2DerToC1C3C2(derInput) + setC1c3c2Input(c1c3c2) + } catch (error) { + alert('转换失败: ' + (error instanceof Error ? error.message : error)) + } + } + + // C1C3C2 转 DER + const handleC1C3C2ToDer = () => { + try { + const der = sm2C1C3C2ToDer(c1c3c2Input) + setDerInput(der) + } catch (error) { + alert('转换失败: ' + (error instanceof Error ? error.message : error)) + } + } + // 处理证书文件上传 const handleCertFileUpload = (e: React.ChangeEvent) => { const file = e.target.files?.[0] @@ -353,7 +375,10 @@ function App() { const handleDecryptSm2 = () => { try { const decrypted = sm2Decrypt(sm2Encrypted, sm2PrivateKey) - setSm2Decrypted(decrypted) + const hexResult = Array.from(decrypted) + .map(byte => byte.toString(16).padStart(2, '0')) + .join('') + setSm2Decrypted(hexResult) } catch (error) { alert('解密失败: ' + (error instanceof Error ? error.message : error)) } @@ -1470,6 +1495,100 @@ function App() { + + {/* DER / C1C3C2 互转卡片 */} +
+

SM2 DER / C1C3C2 密文格式互转

+
+
+ +