Created
October 24, 2022 16:34
-
-
Save eser/c20bd2dddcdb00dc5b2c40f32d074faf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const publicJwk = { | |
"kty": "RSA", | |
"kid": "", | |
"n": "", | |
"e": "AQAB" | |
}; | |
const privateJwk = { | |
"kty": "RSA", | |
"kid": "", | |
"n": "", | |
"e": "AQAB", | |
"d": "", | |
"p": "", | |
"q": "", | |
"dp": "", | |
"dq": "", | |
"qi": "" | |
}; | |
const test = async () => { | |
const privateKey = await globalThis.crypto.subtle.importKey( | |
"jwk", | |
privateJwk, | |
{ name: "RSA-PSS", hash: { name: "SHA-256" } }, | |
false, | |
["sign"], | |
); | |
const publicKey = await globalThis.crypto.subtle.importKey( | |
"jwk", | |
publicJwk, | |
{ name: "RSA-PSS", hash: { name: "SHA-256" } }, | |
false, | |
["verify"], | |
); | |
const encoded = new TextEncoder().encode("Hello World"); | |
const signature = await globalThis.crypto.subtle.sign( | |
{ | |
name: "RSA-PSS", | |
saltLength: 128, //the length of the salt | |
}, | |
privateKey, //from generateKey or importKey above | |
encoded //ArrayBuffer of data you want to sign | |
) | |
const result = await globalThis.crypto.subtle.verify( | |
{ | |
name: "RSA-PSS", | |
saltLength: 128, //the length of the salt | |
}, | |
publicKey, | |
signature, | |
encoded | |
); | |
console.log(result); | |
}; | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment