[英]How to calculate SHA hash of a string in browser JavaScript
Very new to JavaScript I am.我是 JavaScript 的新手。
CryptoJS
module for the frontend.CryptoJS
模块。Closure Library
by Google.Closure Library
。CryptoJS
module.CryptoJS
模块。 But I didn't get the hexadecimal hash. There is a native browser crypto.有一个本机浏览器加密。
A code example for what you want is:您想要的代码示例是:
const text = 'An obscure body in the S-K System, your majesty. The inhabitants refer to it as the planet Earth.';
async function digestMessage(message) {
const encoder = new TextEncoder();
const data = encoder.encode(message);
const hash = await crypto.subtle.digest('SHA-256', data);
return hash;
}
digestMessage(text)
.then(digestBuffer => console.log(digestBuffer.byteLength));
The above example is found here which is a good start for in-browser cryptography.上面的例子可以在这里找到,这是浏览器内加密的一个好的开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.