- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我注意到以下 example (last one)在 MDN 上,这让我相信有一种方法可以将 SubtleCrypto 函数的结果分配给变量。但据我所知/研究过 async/await 只能在 async
函数中使用 await
...
async function sha256(message) {
const msgBuffer = new TextEncoder('utf-8').encode(message); // encode as UTF-8
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); // hash the message
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert ArrayBuffer to Array
const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join(''); // convert bytes to hex string
return hashHex;
}
sha256('abc').then(hash => console.log(hash));
const hash = await sha256('abc');
示例不正确还是我误解了什么?最重要的是;是否可以在没有 .then()
的情况下将 SubtleCrypto/Promise 的结果分配给变量。
对于那些自问我到底为什么需要/想要这个的人。我正在与 redux-persist 结合使用 WebCrypto,但它似乎无法处理基于 Promise 的 transforms .
最佳答案
该示例具有误导性(或不完整),您确实不能在 async function
之外使用 await
。我刚刚编辑了它(MDN 是一个 wiki!)。
Is it possible to assign the outcome of a SubtleCrypto/Promise to a variable without
.then()
.
是的,它将 promise 对象存储在变量中。要访问 promise 结果,您需要使用 then
或 await
。
关于javascript - 异步/等待与 SubtleCrypto 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42939339/
所以我正在尝试实现一些方法来加密然后解密一些数据。我在这方面没有任何经验,我尝试按照一些在线帖子了解如何解决这个问题。 当我将加密的“hello”传递给解密函数时,我得到了这个: let a = im
所以我正在尝试实现一些方法来加密然后解密一些数据。我在这方面没有任何经验,我尝试按照一些在线帖子了解如何解决这个问题。 当我将加密的“hello”传递给解密函数时,我得到了这个: let a = im
我想调用 SubtleCrypto 的方法从一个 worker 。 通常,可以通过窗口上下文中可用的 Crypto.subtle 属性: 例如:window.crypto.subtle.encrypt
我学习一整天the documentation of SubtleCrypto在 Mozilla 工作,无法找到一种使用一个版本的 RSA key 同时进行加密和签名的方法。 我很困惑,因为我能够写
我正在尝试使用 SubtleCrypto.unwrapkey 解开 key ...我的解开算法是: {name: 'RSA-OAEP', hash: Object{name: 'SHA-1'}, mo
我注意到以下 example (last one)在 MDN 上,这让我相信有一种方法可以将 SubtleCrypto 函数的结果分配给变量。但据我所知/研究过 async/await 只能在 asy
我一直在寻找用于加密/解密文本消息的 SublteCrypto,并想提取用于字符串的 key ,但使用相同的接口(interface)“SubtleCrypto”会为 key 生成奇怪的字符串。 现在
所以是的,我的老板想将加密放入他的系统,他希望消息以 js 签名并在 php 中验证。目前,我正在使用 mozilla 的 tinycrypto api 生成 RSA-PSS key 并签名和 php
我有一些使用 SubtleCrypto 的代码来加密 key 并将其存储在数据库中。 对于另一个功能,我必须能够在 Node 12 中对其进行加密。如果没有 SubtleCrypto,我必须在 Cry
我正在尝试使用 Ionic 中的 SubtleCrypto Web API 来使用公钥加密数据。我以 PEM 格式导入 key ,然后将其传递给 window.crypto.subtle.import
我正在尝试让 SubtleCrypto 与 IE 11 一起工作。具体来说,我只是想简单地加密一些东西,让我开始,我已经能够为 AES-CBC 生成一个 key ,但是当我尝试进行加密时出现错误:“类
经过docs之后我找不到使用 WithMD5AndMGF1Padding 使用 RSA-OAEP 加密数据的方法。所以基本上我不知道他们使用什么填充 最佳答案 对于 MGF1,默认值通常是 SHA-1
我正在尝试使用 Web Crypto API 的 SubtleCrypto 接口(interface)验证 JWT 的签名。 我的代码不会验证 token 签名,而 JWT.io 的调试工具会,我不知
这真的很尴尬 几乎在互联网上的任何网站上, window.crypto.subtle 返回 SubtleCrypto {} __proto__: SubtleCrypto 在 chrome 控制台
根据doc使用 PBKDF2 派生密码的简单示例是 return window.crypto.subtle.importKey( 'raw', encoder.encode(pas
我正在使用安全嵌入式芯片 (ATECC508) 使用 secp256r1 曲线生成 ECDSA 消息/签名组合。 Uint8Arrays中芯片输出的信息:message[32]、signature[6
在服务器端我使用PyCryptodome使用 RSA-OAEP(使用 SHA-256)加密消息。 我正在尝试使用 SubtleCrypto 解密消息客户端的 Web Crypto API,但它给了我一
我已经尝试破解这个问题有一段时间了,但没有成功。 服务器端解密使用RSACryptoServiceProvider RSA-OAEP。我无法改变这一点 public void SetEncrypted
我是一名优秀的程序员,十分优秀!