Skip to content

Commit

Permalink
Add usage example of the importKey and exportKey operations
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Mar 27, 2023
1 parent b43d9cb commit b30f6cc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/import_export/import-export-aes-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { crypto } from "k6/x/webcrypto";

export default async function () {
const generatedKey = await crypto.subtle.generateKey(
{
name: "AES-CBC",
length: "256"
},
true,
[
"encrypt",
"decrypt",
]
);

const exportedKey = await crypto.subtle.exportKey("raw", generatedKey);

const importedKey = await crypto.subtle.importKey(
"raw",
exportedKey,
"AES-CBC",
true, ["encrypt", "decrypt"]
);

console.log(JSON.stringify(importedKey))
}

0 comments on commit b30f6cc

Please sign in to comment.