diff --git a/.gitignore b/.gitignore index 2d7beb1..e190a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ out # Temporary files *.tmp -*.temp \ No newline at end of file +*.temp + + +certs \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 5b5082a..27b989c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,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 { parseSm2Cert, parseCertFromFile } from './utils/algorithm/cert' +import { parseSm2Cert, parseCertFromFile, generateRootCert, generateAppCert } from './utils/algorithm/cert' import { hexToUtf8, utf8ToHex, hexToBase64, base64ToHex } from './utils/convert' function App() { @@ -175,6 +175,10 @@ function App() { // 证书工具状态 const [certInfo, setCertInfo] = useState(null) + const [rootCert, setRootCert] = useState('') + const [appCert, setAppCert] = useState('') + const [commonName, setCommonName] = useState('test.example.com') + const [certError, setCertError] = useState('') @@ -292,6 +296,28 @@ function App() { } } + // 处理生成根证书 + const handleGenerateRootCert = () => { + try { + const cert = generateRootCert() + setRootCert(cert) + setCertError('') + } catch (error) { + setCertError((error as Error).message) + } + } + + // 处理生成应用证书 + const handleGenerateAppCert = () => { + try { + const cert = generateAppCert(commonName) + setAppCert(cert) + setCertError('') + } catch (error) { + setCertError((error as Error).message) + } + } + // SM2 生成密钥对 const handleGenerateSm2KeyPair = () => { try { @@ -1450,102 +1476,233 @@ function App() { {/* 证书工具面板 */} {activeTab === 'cert' && (
-

RSA 证书解析

+

证书工具

-
- -
- -
- 选择证书文件 -
-
-
- 支持 .cer, .crt, .pem 格式 -
-
- - {certInfo && ( -
-

证书信息

- -
- -
{certInfo.version}
-
- -
- -
{certInfo.serialNumber}
-
- -
- -
- {Object.entries(certInfo.subject).map(([key, value]) => ( -
{key}: {String(value)}
- ))} -
-
- -
- -
- {Object.entries(certInfo.issuer).map(([key, value]) => ( -
{key}: {String(value)}
- ))} -
-
- -
- -
-
开始: {certInfo.notBefore}
-
结束: {certInfo.notAfter}
-
-
- -
- -
{certInfo.publicKey}
-
- -
- -
- {certInfo.keyUsage.length > 0 ? ( - certInfo.keyUsage.map((usage: string, index: number) => ( -
{usage}
- )) - ) : ( -
- )} -
-
+ {certError && ( +
+ {certError}
)} + + {/* 生成根证书 */} +
+

1. 生成根证书

+ + {rootCert && ( +
+

根证书内容:

+