+ {/* SM2 功能选项卡 */}
+
+
-
-
- {/* 签名/验证 */}
-
-
签名/验证
-
-
-
-
-
-
- {sm2VerifyResult || '验证结果将显示在这里'}
+
+ {/* 加密/解密 */}
+ {sm2ActiveTab === 'encrypt' && (
+
+
加密/解密
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+ )}
+
+ {/* 签名/验证 */}
+ {sm2ActiveTab === 'sign' && (
+
+
签名/验证
+
+
+
+
+
+
+
+
+
+ {sm2VerifyResult || '验证结果将显示在这里'}
+
+
+
+
+
+
+
+ )}
)}
diff --git a/src/types/sm-crypto.d.ts b/src/types/sm-crypto.d.ts
index 1662553..e0acce8 100644
--- a/src/types/sm-crypto.d.ts
+++ b/src/types/sm-crypto.d.ts
@@ -10,6 +10,7 @@ declare module 'sm-crypto' {
doDecrypt: (ciphertext: string, privateKey: string) => string;
doSignature: (message: string | Uint8Array, privateKey: string, options?: { hash?: boolean, der?: boolean, userId?: string, publicKey?: string, pointPool?: any[] }) => string;
doVerifySignature: (message: string | Uint8Array, signature: string, publicKey: string, options?: { hash?: boolean, der?: boolean, userId?: string }) => boolean;
+ getPublicKeyFromPrivateKey: (privateKey: string) => string;
};
export const sm3: {
diff --git a/src/utils/algorithm/sm2.ts b/src/utils/algorithm/sm2.ts
index 26d90f8..e32bbc1 100644
--- a/src/utils/algorithm/sm2.ts
+++ b/src/utils/algorithm/sm2.ts
@@ -15,12 +15,15 @@ export const sm2GenerateKeyPair = (): { privateKey: string; publicKey: string }
// SM2 从私钥计算公钥
export const sm2GetPublicKeyFromPrivateKey = (privateKey: string): string => {
// 验证私钥是否为有效的 hex 字符串
+ if (!privateKey) {
+ throw new Error('Private key is required')
+ }
if (!isValidHex(privateKey)) {
throw new Error('Invalid private key: must be hex string')
}
- const keypair = sm2.generateKeyPairHex(privateKey)
- return keypair.publicKey
+ const publicKey = sm2.getPublicKeyFromPrivateKey(privateKey)
+ return publicKey
}
// SM2 加密
diff --git a/src/version.js b/src/version.js
index 3feece3..ce32ffa 100644
--- a/src/version.js
+++ b/src/version.js
@@ -1 +1 @@
-export const VERSION = "V1.0-20260418053331";
\ No newline at end of file
+export const VERSION = "V1.0-20260418065443";
\ No newline at end of file