From 2303d1ae1e2bf78a730cb782b174bc1c7d0ada84 Mon Sep 17 00:00:00 2001 From: src48597962 <48597962@qq.com> Date: Tue, 7 Mar 2023 09:41:27 +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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index f0de8493..924c4569 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,7 @@ +eval(getCryptoJS()); function sha256(str) { const data = new Uint8Array(Array.from(str, c => c.charCodeAt(0))); - return crypto.subtle.digest('SHA-256', data).then(hashBuffer => { + return CryptoJS.subtle.digest('SHA-256', data).then(hashBuffer => { const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join(''); return hashHex; @@ -8,7 +9,7 @@ function sha256(str) { } function getRandomBytes(len) { const arr = new Uint8Array(len); - window.crypto.getRandomValues(arr); + CryptoJS.getRandomValues(arr); return Array.from(arr, (dec) => ('0' + dec.toString(16)).substr(-2)).join(''); } function toHex(buf) {