-
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.
1 parent
8c9ad7a
commit 5dad531
Showing
11 changed files
with
205 additions
and
248 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import { crypto } from "k6/x/webcrypto"; | ||
|
||
export default async function () { | ||
try { | ||
const key = await crypto.subtle.generateKey( | ||
{ | ||
name: "HMAC", | ||
hash: { name: "SHA-512" }, | ||
length: 256, | ||
}, | ||
true, | ||
["sign", "verify"] | ||
); | ||
console.log(JSON.stringify(key)); | ||
} catch (e) { | ||
console.log(JSON.stringify(e)); | ||
} | ||
const key = await crypto.subtle.generateKey( | ||
{ | ||
name: "HMAC", | ||
hash: { name: "SHA-512" }, | ||
length: 256, | ||
}, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log(JSON.stringify(key)); | ||
} |
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,28 +1,24 @@ | ||
import { crypto } from "k6/x/webcrypto"; | ||
|
||
export default async function () { | ||
try { | ||
const generatedKey = await crypto.subtle.generateKey( | ||
{ | ||
name: "HMAC", | ||
hash: { name: "SHA-256" }, | ||
}, | ||
true, | ||
["sign", "verify"] | ||
); | ||
const generatedKey = await crypto.subtle.generateKey( | ||
{ | ||
name: "HMAC", | ||
hash: { name: "SHA-256" }, | ||
}, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
const exportedKey = await crypto.subtle.exportKey("raw", generatedKey); | ||
const exportedKey = await crypto.subtle.exportKey("raw", generatedKey); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"raw", | ||
exportedKey, | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
true, | ||
["sign", "verify"] | ||
); | ||
const importedKey = await crypto.subtle.importKey( | ||
"raw", | ||
exportedKey, | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log(JSON.stringify(importedKey)); | ||
} catch (err) { | ||
console.log(JSON.stringify(err)); | ||
} | ||
console.log(JSON.stringify(importedKey)); | ||
} |
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,36 +1,32 @@ | ||
import { crypto } from "k6/x/webcrypto"; | ||
|
||
export default async function () { | ||
try { | ||
const generatedKey = await crypto.subtle.generateKey( | ||
{ | ||
name: "AES-CBC", | ||
length: "256", | ||
}, | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
console.log("generated: " + JSON.stringify(generatedKey)); | ||
|
||
const exportedKey = await crypto.subtle.exportKey("jwk", generatedKey); | ||
|
||
console.log("exported: " + JSON.stringify(exportedKey)); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
exportedKey, | ||
"AES-CBC", | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
console.log("imported: " + JSON.stringify(importedKey)); | ||
|
||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
|
||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} catch (err) { | ||
console.log(JSON.stringify(err)); | ||
} | ||
const generatedKey = await crypto.subtle.generateKey( | ||
{ | ||
name: "AES-CBC", | ||
length: "256", | ||
}, | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
console.log("generated: " + JSON.stringify(generatedKey)); | ||
|
||
const exportedKey = await crypto.subtle.exportKey("jwk", generatedKey); | ||
|
||
console.log("exported: " + JSON.stringify(exportedKey)); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
exportedKey, | ||
"AES-CBC", | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
console.log("imported: " + JSON.stringify(importedKey)); | ||
|
||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
|
||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} |
40 changes: 18 additions & 22 deletions
40
examples/import_export/import-export-jwk-aes-static-key.js
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,31 +1,27 @@ | ||
import { crypto } from "k6/x/webcrypto"; | ||
|
||
export default async function () { | ||
try { | ||
const jwk = { | ||
alg: "A256CBC", | ||
ext: true, | ||
k: "LhR2VJFb1NJ8HORgOn7LNKLXhUqPsTjC65UAWFb4GKI", | ||
key_ops: ["encrypt", "decrypt"], | ||
kty: "oct", | ||
}; | ||
const jwk = { | ||
alg: "A256CBC", | ||
ext: true, | ||
k: "LhR2VJFb1NJ8HORgOn7LNKLXhUqPsTjC65UAWFb4GKI", | ||
key_ops: ["encrypt", "decrypt"], | ||
kty: "oct", | ||
}; | ||
|
||
console.log("static key: " + JSON.stringify(jwk)); | ||
console.log("static key: " + JSON.stringify(jwk)); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
jwk, | ||
{ name: "AES-CBC", length: 256 }, | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
jwk, | ||
{ name: "AES-CBC", length: 256 }, | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
console.log("imported: " + JSON.stringify(importedKey)); | ||
console.log("imported: " + JSON.stringify(importedKey)); | ||
|
||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
|
||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} catch (err) { | ||
console.log(JSON.stringify(err)); | ||
} | ||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} |
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,36 +1,32 @@ | ||
import { crypto } from "k6/x/webcrypto"; | ||
|
||
export default async function () { | ||
try { | ||
const generatedKey = await crypto.subtle.generateKey( | ||
{ | ||
name: "HMAC", | ||
hash: { name: "SHA-256" }, | ||
}, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log("generated: " + JSON.stringify(generatedKey)); | ||
|
||
const exportedKey = await crypto.subtle.exportKey("jwk", generatedKey); | ||
|
||
console.log("exported: " + JSON.stringify(exportedKey)); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
exportedKey, | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log("imported: " + JSON.stringify(importedKey)); | ||
|
||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
|
||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} catch (err) { | ||
console.log(JSON.stringify(err)); | ||
} | ||
const generatedKey = await crypto.subtle.generateKey( | ||
{ | ||
name: "HMAC", | ||
hash: { name: "SHA-256" }, | ||
}, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log("generated: " + JSON.stringify(generatedKey)); | ||
|
||
const exportedKey = await crypto.subtle.exportKey("jwk", generatedKey); | ||
|
||
console.log("exported: " + JSON.stringify(exportedKey)); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
exportedKey, | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log("imported: " + JSON.stringify(importedKey)); | ||
|
||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
|
||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} |
40 changes: 18 additions & 22 deletions
40
examples/import_export/import-export-jwk-hmac-static-key.js
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,31 +1,27 @@ | ||
import { crypto } from "k6/x/webcrypto"; | ||
|
||
export default async function () { | ||
try { | ||
const jwk = { | ||
alg: "HS256", | ||
ext: true, | ||
k: "H6gLp3lw7w27NrPUn00WpcKU-IJojJdNzhL_8F6se2k", | ||
key_ops: ["sign", "verify"], | ||
kty: "oct", | ||
}; | ||
const jwk = { | ||
alg: "HS256", | ||
ext: true, | ||
k: "H6gLp3lw7w27NrPUn00WpcKU-IJojJdNzhL_8F6se2k", | ||
key_ops: ["sign", "verify"], | ||
kty: "oct", | ||
}; | ||
|
||
console.log("static key: " + JSON.stringify(jwk)); | ||
console.log("static key: " + JSON.stringify(jwk)); | ||
|
||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
jwk, | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
true, | ||
["sign", "verify"] | ||
); | ||
const importedKey = await crypto.subtle.importKey( | ||
"jwk", | ||
jwk, | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
true, | ||
["sign", "verify"] | ||
); | ||
|
||
console.log("imported: " + JSON.stringify(importedKey)); | ||
console.log("imported: " + JSON.stringify(importedKey)); | ||
|
||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); | ||
|
||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} catch (err) { | ||
console.log(JSON.stringify(err)); | ||
} | ||
console.log("exported again: " + JSON.stringify(exportedAgain)); | ||
} |
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