Subtle中的SHA-1的SubtleCrypto.digest()失败

时间:2018-02-27 21:23:16

标签: microsoft-edge sha1 webcryptoapi

我正在尝试使用Web Crypto API生成字符串的SHA-1哈希。我用来执行此操作的代码几乎是MDN SubtleCrypto.digest() page中的第二个示例。

async function getHash(value, algorithm = 'SHA-1') {
  let msgBuffer = new TextEncoder('utf-8').encode(value);
  let hashBuffer = await crypto.subtle.digest(algorithm, msgBuffer);
  let hashArray = Array.from(new Uint8Array(hashBuffer));
  return hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
}

请参阅this JSFiddle了解演示。

我也在Edge中使用this TextEncoder Polyfill。它在Firefox和Chrome中运行良好,但在Microsoft Edge中,我只收到错误消息" SHA-1"。

我无法找到有关此错误的任何信息。有人知道出了什么问题吗?有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

“Edge不支持SHA1”,请尝试Threshold