Which key algorithms are available? #13465
-
Here the docs just have it as a string: interface Algorithm {
name: string;
} But I can't seem to figure out what string goes there. I'm trying to create a jwt for a github App following these docs: I have the private key github gave me locally and this is my code: const keyAlgorithm = "???"
const key = await Deno.readFile('key')
const pk = await crypto.subtle.importKey(
"raw",
key,
{ name: keyAlgorithm, hash: "SHA-256" },
true,
["sign", "verify"]
) But I can't seem to figure out the right value for |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think its supposed to be |
Beta Was this translation helpful? Give feedback.
-
You're looking for https://doc.deno.land/deno/stable/~/RsaHashedImportParams If you read Github docs carefully it's a PEM-encoded PKCS#1 RSAPrivateKey. First, You need to convert it to pkcs8:
Then extract the DER encoded material out of the PEM and pass it to WebCrypto: const keyFile = await Deno.readTextFile('private-key-pkcs8.pem');
const pemHeader = "-----BEGIN PRIVATE KEY-----";
const pemFooter = "-----END PRIVATE KEY-----";
const pemContents = keyFile.substring(
pemHeader.length,
keyFile.length - pemFooter.length,
);
const binaryDerString = atob(pemContents);
const binaryDer = new Uint8Array(binaryDerString.length);
for (let i = 0; i < binaryDerString.length; i++) {
binaryDer[i] = binaryDerString.charCodeAt(i);
}
const pk = await crypto.subtle.importKey(
"pkcs8",
binaryDer,
{ name: "RSA-PSS", hash: "SHA-256" },
true,
["sign", "verify"]
); Related: |
Beta Was this translation helpful? Give feedback.
You're looking for https://doc.deno.land/deno/stable/~/RsaHashedImportParams
If you read Github docs carefully it's a PEM-encoded PKCS#1 RSAPrivateKey. First, You need to convert it to pkcs8:
Then extract the DER encoded material out of the PEM and pass it to WebCrypto: