summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/webcrypto_test.ts24
-rw-r--r--ext/crypto/00_crypto.js7
2 files changed, 29 insertions, 2 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 2dda71e6f..7a2bed758 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -357,6 +357,30 @@ unitTest(async function subtleCryptoHmacImportExport() {
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
const pkcs8TestVectors = [
// rsaEncryption
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index 5eb283b22..50ee9a7db 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -24,6 +24,7 @@
StringPrototypeToUpperCase,
StringPrototypeReplace,
StringPrototypeCharCodeAt,
+ StringFromCharCode,
Symbol,
SymbolFor,
SymbolToStringTag,
@@ -140,9 +141,11 @@
}
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);
-
return StringPrototypeReplace(base64String, /=/g, "");
}