mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
feat(extensions/crypto): implement verify() for RSA (#11312)
This commit is contained in:
parent
e95c0c85fa
commit
00484d24ba
5 changed files with 321 additions and 2 deletions
|
@ -1,5 +1,54 @@
|
|||
import { assert, assertEquals, unitTest } from "./test_util.ts";
|
||||
|
||||
// TODO(@littledivy): Remove this when we enable WPT for sign_verify
|
||||
unitTest(async function testSignVerify() {
|
||||
const subtle = window.crypto.subtle;
|
||||
assert(subtle);
|
||||
for (const algorithm of ["RSA-PSS", "RSASSA-PKCS1-v1_5"]) {
|
||||
for (
|
||||
const hash of [
|
||||
"SHA-1",
|
||||
"SHA-256",
|
||||
"SHA-384",
|
||||
"SHA-512",
|
||||
]
|
||||
) {
|
||||
const keyPair = await subtle.generateKey(
|
||||
{
|
||||
name: algorithm,
|
||||
modulusLength: 2048,
|
||||
publicExponent: new Uint8Array([1, 0, 1]),
|
||||
hash,
|
||||
},
|
||||
true,
|
||||
["sign", "verify"],
|
||||
);
|
||||
|
||||
const data = new Uint8Array([1, 2, 3]);
|
||||
const signAlgorithm = { name: algorithm, saltLength: 32 };
|
||||
|
||||
const signature = await subtle.sign(
|
||||
signAlgorithm,
|
||||
keyPair.privateKey,
|
||||
data,
|
||||
);
|
||||
|
||||
assert(signature);
|
||||
assert(signature.byteLength > 0);
|
||||
assert(signature.byteLength % 8 == 0);
|
||||
assert(signature instanceof ArrayBuffer);
|
||||
|
||||
const verified = await subtle.verify(
|
||||
signAlgorithm,
|
||||
keyPair.publicKey,
|
||||
signature,
|
||||
data,
|
||||
);
|
||||
assert(verified);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
unitTest(async function testGenerateRSAKey() {
|
||||
const subtle = window.crypto.subtle;
|
||||
assert(subtle);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue