From 628452d114848a3555f2a45c7623f378ad3b6aed Mon Sep 17 00:00:00 2001 From: src48597962 <48597962@qq.com> Date: Tue, 7 Mar 2023 11:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'test.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test.js b/test.js index fa30bc75..ee019384 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,8 @@ -require("https://cdn.jsdelivr.net/npm/crypto-es/crypto-es.js") -require("https://cdn.jsdelivr.net/npm/elliptic/dist/elliptic.min.js") +require("https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js") +require("https://cdnjs.cloudflare.com/ajax/libs/elliptic/6.5.4/elliptic.min.js") // 生成随机私钥 -const privateKey = CryptoES.lib.WordArray.random(32).toString(); +const privateKey = CryptoJS.lib.WordArray.random(32).toString(); // 根据私钥生成公钥 const ec = new elliptic.ec('secp256k1'); const publicKey = ec.keyFromPrivate(privateKey).getPublic().encode('hex'); @@ -13,7 +13,7 @@ const userId = "3426axxxxx04e1ea9ee01bd998d06d4"; let nonce = 0; const message = `${appId}:${deviceId}:${userId}:${nonce}`; // 计算消息哈希 -const messageHash = CryptoES.SHA256(CryptoES.enc.Utf8.parse(message)).toString(); +const messageHash = CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(message)).toString(); // 对哈希值进行签名 const signKey = ec.keyFromPrivate(privateKey); const signature = signKey.sign(messageHash).toDER('hex');