CryptoKey:usages 属性
值
示例
js
const rawKey = window.crypto.getRandomValues(new Uint8Array(16));
// Import an AES secret key from an ArrayBuffer containing the raw bytes.
// Takes an ArrayBuffer string containing the bytes, and returns a Promise
// that will resolve to a CryptoKey representing the secret key.
function importSecretKey(rawKey) {
return window.crypto.subtle.importKey("raw", rawKey, "AES-GCM", true, [
"encrypt",
"decrypt",
]);
}
const key = importSecretKey(rawKey);
console.log(
`The following usages are reported for this key: ${key.usages.toString()}`,
);
规范
规范 |
---|
Web 加密 API # dom-cryptokey-usages |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。