CryptoKey: thuộc tính usages
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Thuộc tính chỉ đọc usages của giao diện CryptoKey cho biết có thể làm gì với khóa.
Giá trị
Một Array các chuỗi từ danh sách sau:
"encrypt": Khóa có thể được dùng để mã hóa thông điệp."decrypt": Khóa có thể được dùng để giải mã thông điệp."sign": Khóa có thể được dùng để ký thông điệp."verify": Khóa có thể được dùng để xác minh chữ ký."deriveKey": Khóa có thể được dùng để suy ra khóa mới."deriveBits": Khóa có thể được dùng để suy ra các bit."wrapKey": Khóa có thể được dùng để bọc một khóa."unwrapKey": Khóa có thể được dùng để mở bọc một khóa.
Ví dụ
js
const rawKey = window.crypto.getRandomValues(new Uint8Array(16));
// Nhập một khóa bí mật AES từ một ArrayBuffer chứa các byte thô.
// Hàm nhận một ArrayBuffer chứa các byte và trả về một Promise
// sẽ được resolve thành một CryptoKey đại diện cho khóa bí mật.
function importSecretKey(rawKey) {
return window.crypto.subtle.importKey("raw", rawKey, "AES-GCM", true, [
"encrypt",
"decrypt",
]);
}
importSecretKey(rawKey).then((key) =>
console.log(
`Các mục đích sử dụng được báo cáo cho khóa này là: ${key.usages.toString()}`,
),
);
Thông số kỹ thuật
| Specification |
|---|
| Web Cryptography Level 2> # dom-cryptokey-usages> |