diff --git a/src/utils/signatureVerifier.ts b/src/utils/signatureVerifier.ts index ad4f95d..10d8759 100644 --- a/src/utils/signatureVerifier.ts +++ b/src/utils/signatureVerifier.ts @@ -33,12 +33,19 @@ export async function pem2_P256key(filePath: string) { const publicKeyBytes = await Deno.readFile(filePath); const pemKey = new TextDecoder().decode(publicKeyBytes); + return pemString2_P256key(pemKey) +} + + +export async function pemString2_P256key(pemString: string) { + + // fetch the part of the PEM string between header and footer const pemHeader = "-----BEGIN PUBLIC KEY-----"; const pemFooter = "-----END PUBLIC KEY-----"; - const pemContents = pemKey.substring( + const pemContents = pemString.substring( pemHeader.length, - pemKey.length - pemFooter.length - 1, + pemString.length - pemFooter.length - 1, ); // base64 decode the string to get the binary data // convert from a binary string to an ArrayBuffer