diff --git a/src/App.tsx b/src/App.tsx index b4a10a6..f713853 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 { hexToUtf8, utf8ToHex } from './utils/convert' +import { hexToUtf8, utf8ToHex, hexToBase64, base64ToHex } from './utils/convert' function App() { const [activeTab, setActiveTab] = useState('sm3') @@ -67,6 +67,7 @@ function App() { // 转换工具状态 const [hexInput, setHexInput] = useState('') const [utf8Input, setUtf8Input] = useState('') + const [base64Input, setBase64Input] = useState('') @@ -130,6 +131,26 @@ function App() { } } + // Hex 转 Base64 + const handleHexToBase64 = () => { + try { + const base64 = hexToBase64(hexInput) + setBase64Input(base64) + } catch (error) { + alert('转换失败: ' + error) + } + } + + // Base64 转 Hex + const handleBase64ToHex = () => { + try { + const hex = base64ToHex(base64Input) + setHexInput(hex) + } catch (error) { + alert('转换失败: ' + error) + } + } + // SM2 生成密钥对 const handleGenerateSm2KeyPair = () => { try { @@ -962,7 +983,7 @@ function App() { {/* 转换工具面板 */} {activeTab === 'convert' && (