mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
fix(ext/crypto): don't use core.decode for encoding jwk keys (#12088)
This commit is contained in:
parent
3c97dbf06b
commit
9270cad67c
2 changed files with 29 additions and 2 deletions
|
@ -357,6 +357,30 @@ unitTest(async function subtleCryptoHmacImportExport() {
|
||||||
assertEquals(exportedKey2, jwk);
|
assertEquals(exportedKey2, jwk);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/denoland/deno/issues/12085
|
||||||
|
unitTest(async function generateImportHmacJwk() {
|
||||||
|
const key = await crypto.subtle.generateKey(
|
||||||
|
{
|
||||||
|
name: "HMAC",
|
||||||
|
hash: "SHA-512",
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
["sign"],
|
||||||
|
);
|
||||||
|
assert(key);
|
||||||
|
assertEquals(key.type, "secret");
|
||||||
|
assertEquals(key.extractable, true);
|
||||||
|
assertEquals(key.usages, ["sign"]);
|
||||||
|
|
||||||
|
const exportedKey = await crypto.subtle.exportKey("jwk", key);
|
||||||
|
assertEquals(exportedKey.kty, "oct");
|
||||||
|
assertEquals(exportedKey.alg, "HS512");
|
||||||
|
assertEquals(exportedKey.key_ops, ["sign"]);
|
||||||
|
assertEquals(exportedKey.ext, true);
|
||||||
|
assert(typeof exportedKey.k == "string");
|
||||||
|
assertEquals(exportedKey.k.length, 171);
|
||||||
|
});
|
||||||
|
|
||||||
// 2048-bits publicExponent=65537
|
// 2048-bits publicExponent=65537
|
||||||
const pkcs8TestVectors = [
|
const pkcs8TestVectors = [
|
||||||
// rsaEncryption
|
// rsaEncryption
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
StringPrototypeToUpperCase,
|
StringPrototypeToUpperCase,
|
||||||
StringPrototypeReplace,
|
StringPrototypeReplace,
|
||||||
StringPrototypeCharCodeAt,
|
StringPrototypeCharCodeAt,
|
||||||
|
StringFromCharCode,
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
SymbolToStringTag,
|
SymbolToStringTag,
|
||||||
|
@ -140,9 +141,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpaddedBase64(bytes) {
|
function unpaddedBase64(bytes) {
|
||||||
const binaryString = core.decode(bytes);
|
let binaryString = "";
|
||||||
|
for (let i = 0; i < bytes.length; i++) {
|
||||||
|
binaryString += StringFromCharCode(bytes[i]);
|
||||||
|
}
|
||||||
const base64String = btoa(binaryString);
|
const base64String = btoa(binaryString);
|
||||||
|
|
||||||
return StringPrototypeReplace(base64String, /=/g, "");
|
return StringPrototypeReplace(base64String, /=/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue