W3 specification
const key = await crypto.subtle.generateKey(
{
name: "AES-KW",
length: 128, // 128, 192, or 256
},
false, // extractable
["wrapKey", "unwrapKey"], // key usages
);
const key = await crypto.subtle.importKey(
"raw", // raw or jwk
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]), // raw data
"AES-KW",
false, // extractable
["encrypt", "decrypt"],
);
const raw = await crypto.subtle.exportKey(
"raw", // raw or jwk
key,
);
const iv = crypto.getRandomValues(new Uint8Array(16));
const wrappedKey = await crypto.subtle.wrapKey(
"pkcs8", // raw, pkcs8, spki, or jwk
anyKey, // Crypto key
key, // AES key
"AES-KW",
);
const unwrappedKey = await crypto.subtle.unwrapKey(
"pkcs8", // raw, pkcs8, spki, or jwk
wrappedKey, // BufferSource
key, // AES key
"AES-KW",
{
name: "RSA-PSS",
hash: "SHA-256",
}
false, // extractable
["sign", "verify"],
);