diff --git a/package.json b/package.json index dafca55..f176d67 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", - "test": "jest" + "test": "jest", + "public": "tsc && vite build && surge dist seckit.surge.sh" }, "dependencies": { "gm-crypto": "*", diff --git a/src/App.tsx b/src/App.tsx index 577baa0..f341b31 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,25 +1,19 @@ import { useState } from 'react' -import { generateSm2KeyPair, sm2Encrypt, sm2Decrypt } from './utils/algorithm/sm2' + import { sm3Digest, sm3Hmac } from './utils/algorithm/sm3' import { sm4Encrypt, sm4Decrypt } from './utils/algorithm/sm4' import { hexToUtf8, utf8ToHex } from './utils/convert' function App() { - const [activeTab, setActiveTab] = useState('sm2') + const [activeTab, setActiveTab] = useState('sm3') - // SM2 状态 - const [sm2PrivateKey, setSm2PrivateKey] = useState('') - const [sm2PublicKey, setSm2PublicKey] = useState('') - const [sm2Message, setSm2Message] = useState('') - const [sm2Signature, setSm2Signature] = useState('') - const [sm2Encrypted, setSm2Encrypted] = useState('') - const [sm2Decrypted, setSm2Decrypted] = useState('') + // SM3 状态 const [sm3Message, setSm3Message] = useState('') const [sm3Result, setSm3Result] = useState('') - const [sm3MacKey, setSm3MacKey] = useState('') - const [sm3MacResult, setSm3MacResult] = useState('') + const [sm3HmacKey, setSm3HmacKey] = useState('') + const [sm3HmacResult, setSm3HmacResult] = useState('') // SM4 状态 const [sm4Key, setSm4Key] = useState('') @@ -34,66 +28,7 @@ function App() { const [hexInput, setHexInput] = useState('') const [utf8Input, setUtf8Input] = useState('') - // SM2 生成密钥对 - const handleGenerateSm2KeyPair = () => { - try { - const { privateKey, publicKey } = generateSm2KeyPair() - setSm2PrivateKey(privateKey) - setSm2PublicKey(publicKey) - } catch (error) { - alert('生成密钥对失败: ' + error) - } - } - // SM2 从私钥计算公钥 - const calculateSm2PublicKey = () => { - try { - // 简化处理,实际项目中可能需要使用正确的 API - alert('从私钥计算公钥功能需要正确的 API 支持') - } catch (error) { - alert('计算公钥失败: ' + error) - } - } - - // SM2 签名 - const signSm2 = () => { - try { - // 简化处理,实际项目中可能需要使用正确的 API - alert('签名功能需要正确的 API 支持') - } catch (error) { - alert('签名失败: ' + error) - } - } - - // SM2 验签 - const verifySm2 = () => { - try { - // 简化处理,实际项目中可能需要使用正确的 API - alert('验签功能需要正确的 API 支持') - } catch (error) { - alert('验签失败: ' + error) - } - } - - // SM2 公钥加密 - const handleEncryptSm2 = () => { - try { - const encrypted = sm2Encrypt(sm2Message, sm2PublicKey) - setSm2Encrypted(encrypted) - } catch (error) { - alert('加密失败: ' + (error instanceof Error ? error.message : error)) - } - } - - // SM2 私钥解密 - const handleDecryptSm2 = () => { - try { - const decrypted = sm2Decrypt(sm2Encrypted, sm2PrivateKey) - setSm2Decrypted(decrypted) - } catch (error) { - alert('解密失败: ' + (error instanceof Error ? error.message : error)) - } - } // SM3 计算 const handleCalculateSm3 = () => { @@ -105,13 +40,13 @@ function App() { } } - // SM3 MAC 计算 - const calculateSm3Mac = () => { + // SM3 HMAC 计算 + const calculateSm3Hmac = () => { try { - const result = sm3Hmac(sm3MacKey, sm3Message) - setSm3MacResult(result) + const result = sm3Hmac(sm3HmacKey, sm3Message) + setSm3HmacResult(result) } catch (error) { - alert('MAC 计算失败: ' + (error instanceof Error ? error.message : error)) + alert('HMAC 计算失败: ' + (error instanceof Error ? error.message : error)) } } @@ -160,12 +95,6 @@ function App() {