async function verifySignature(publicKeyBase64, base64Data, base64Signature) { // Decode base64 strings const publicKeyRaw = Uint8Array.from(atob(publicKeyBase64), c => c.charCodeAt(0)); const data = Uint8Array.from(atob(base64Data), c => c.charCodeAt(0)); const signature = Uint8Array.from(atob(base64Signature), c => c.charCodeAt(0)); // Import the public key const publicKey = await crypto.subtle.importKey( 'spki', publicKeyRaw, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['verify'] ); // Verify the signature const isValid = await crypto.subtle.verify( { name: 'ECDSA', hash: { name: 'SHA-256' } }, publicKey, signature, data ); return isValid; } // Example usage const publicKeyBase64 = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbfwR+RJudXscgRBRpKX1XFDy3PyudDxz/SfnRi1fT8ekpfBd2O1uoz7jr3Z8nKzxA69EUQ+eFCFI3zeubPWU7w=="; const base64Data = "AAAAAAGCJ8CenAABw1XuU9aeaKreBOXGzCAs+sEfvKpn6aK6emTO0q7IzNAAAZswggGXoAMCAQICFEZvaJ+8w74T5j3b0UonfEHNVtJxMAoGCCqGSM49BAMDMDcxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEeMBwGA1UEAxMVc2lnc3RvcmUtaW50ZXJtZWRpYXRlMB4XDTIyMDcyMjIxMTE1MVoXDTIyMDcyMjIxMjE1MVowADBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFnyqyvCsvnbmOcRIHscYdn4UvukVsQKHc3WkN6e+cL7phM6VlzMp2r97qY1KhsNvPmT506QGJK8pP85d6SkVBCjgbcwgbQwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUFBwMDMB0GA1UdDgQWBBQc4BNuLlzfGwl1gqkyaQX/xA9VfzAfBgNVHSMEGDAWgBTf0+nPViQRlvmo2OkoVaLGLhhkPzAfBgNVHREBAf8EFTATgRFicmlhbkBkZWhhbWVyLmNvbTAsBgorBgEEAYO/MAEBBB5odHRwczovL2dpdGh1Yi5jb20vbG9naW4vb2F1dGgAAA=="; // "Hello world" in base64 const base64Signature = "MEUCIQC57LC1KG/uog1EKkCdqMUmC9audrMR1x+s7/HH/JPIXAIgTjXlXWKaGoT5qIXnYh2bOvntjn/9AmBnkTm9p2TF59A="; verifySignature(publicKeyBase64, base64Data, base64Signature) .then(isValid => console.log(`Signature valid: ${isValid}`)) .catch(err => console.error(`Error: ${err}`));