From b757597db9089cc35edc4179f4a5e5ef06b783dc Mon Sep 17 00:00:00 2001 From: cheney Date: Sat, 18 Apr 2026 15:04:19 +0800 Subject: [PATCH] =?UTF-8?q?base64=20=E6=A0=BC=E5=BC=8F=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 85 ++++++++++++++++++++++++++++++++++++-- src/utils/convert/index.ts | 12 ++++++ src/version.js | 2 +- 3 files changed, 94 insertions(+), 5 deletions(-) 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' && (
-

Hex / UTF8 转换

+

Hex / UTF8 / Base64 转换

@@ -1020,8 +1041,64 @@ function App() { resize: 'vertical' }} /> +
+ + +
+
+ +
+ +