From b95f20a474a84d5a98dc4d5072a432ca18a94b4c Mon Sep 17 00:00:00 2001 From: Christian Risi <75698846+CnF-Gris@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:13:20 +0100 Subject: [PATCH] V0.7.1 Arroyo Toad Added a method to transform a string to a public key --- src/utils/signatureVerifier.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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