@@ -285,54 +285,20 @@ actual class JWKKey actual constructor(
285285 detachedPlaintext : ByteArray? ,
286286 customSignatureAlgorithm : String?
287287 ): Result <ByteArray > {
288- /* runCatching {
289- require(detachedPlaintext != null) { "Detached plaintext cannot be null." }
290-
291- // Assume a method exists to get the public key in PEM format.
292- val pemString = exportPEM()
293-
294- // 1. Parse the public key from PEM format to a raw binary ArrayBuffer.
295- val publicKeyData = parsePemToBinary(pemString)
296-
297- // 2. Get the algorithm parameters required by the Web Crypto API.
298- val jwsAlgorithm = keyType.jwsAlg
299- val cryptoParams = getVerificationWebCryptoParams()
300-
301- // 3. Import the public key to create a CryptoKey object for verification.
302- val cryptoKey = WebCrypto.subtle.importKey(
303- "spki", // Public key format for public keys
304- publicKeyData, // The raw key data
305- cryptoParams.importAlgorithm,
306- true,
307- arrayOf("verify") // Specify that this key will be used for verification.
308- ).await()
309-
310- // 4. IMPORTANT: Ensure the signature is in the IEEE P1363 format required by `subtle.verify`.
311- val p1363Signature = convertDERtoIEEEP1363(signed)
312- val signatureBuffer = (p1363Signature as Int8Array).buffer
313-
314- // 5. Call `subtle.verify` with the key, signature, and original data.
315- val isValid = WebCrypto.subtle.verify(
316- cryptoParams.signAlgorithm,
317- cryptoKey,
318- signatureBuffer,
319- Uint8Array(detachedPlaintext.toTypedArray())
320- ).await()
321-
322- // 6. Check the result and return the plaintext or throw an exception.
323- if (isValid) {
324- detachedPlaintext
325- } else {
326- throw IllegalArgumentException("Signature verification failed.")
327- }*/
328-
329-
330288 return runCatching {
289+ // needs to be same as in JVM implementation
290+ val hashingAlgorithm = when (keyType) {
291+ KeyType .Ed25519 -> null
292+ KeyType .secp256k1 -> " SHA256"
293+ KeyType .secp256r1 -> " SHA256"
294+ KeyType .secp384r1 -> " SHA384"
295+ KeyType .secp521r1 -> " SHA512"
296+ KeyType .RSA -> " SHA256"
297+ KeyType .RSA3072 -> " SHA384"
298+ KeyType .RSA4096 -> " SHA512"
299+ }
331300 val verified = crypto.verify(
332- when (keyType) {
333- KeyType .Ed25519 -> null
334- else -> " sha256"
335- },
301+ hashingAlgorithm,
336302 detachedPlaintext ? : signed,
337303 getPublicKey().exportPEM(),
338304 signed
0 commit comments