该接口用于密钥导入,导出、以及随机生成,详细定义及用法参见MDN官方文档importKey、exportKey、generateKey。
async function handle() { var algorithm = {name: "HMAC", hash: {name: "SHA-512"}}; var key = await crypto.subtle.generateKey(algorithm, true, ['sign', 'verify']); var raw_key = await crypto.subtle.exportKey("Raw", key); var import_key = await crypto.subtle.importKey("Raw", raw_key, algorithm, true, ['sign', 'verify']); }