-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: unifying of import/export examples
- Loading branch information
1 parent
1602444
commit c2a732e
Showing
13 changed files
with
420 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,45 @@ | ||
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)); | ||
crypto.subtle | ||
.generateKey( | ||
{ | ||
name: "AES-CBC", | ||
length: "256", | ||
}, | ||
true, | ||
["encrypt", "decrypt"] | ||
) | ||
.then( | ||
(key) => { | ||
// export key | ||
crypto.subtle.exportKey("raw", key).then( | ||
(exportedKey) => { | ||
// try to import the key again | ||
crypto.subtle | ||
.importKey("raw", exportedKey, "AES-CBC", true, [ | ||
"encrypt", | ||
"decrypt", | ||
]) | ||
.then( | ||
(importedKey) => { | ||
console.log( | ||
"operation successful, imported: " + | ||
JSON.stringify(importedKey) | ||
); | ||
}, | ||
(err) => { | ||
console.error("key import, got unexpected error: " + err); | ||
} | ||
); | ||
}, | ||
(err) => { | ||
console.error("key export, got unexpected error: " + err); | ||
} | ||
); | ||
}, | ||
(err) => { | ||
console.error("key generation, got unexpected error: " + err); | ||
} | ||
); | ||
} |
Oops, something went wrong.