bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
230 stars 121 forks source link

ECDSA verifier #192

Closed dlewis2017 closed 1 year ago

dlewis2017 commented 1 year ago

Hello,

I'm trying to verify the signature of bytes but having trouble getting it to work. I've also tried signing the bytes myself (with this algorithm) and verifying it myself, but the result keeps coming back as false

Verifier:

bool verifyCert(Certificate fristCert, Certificate secondCert) {
    ECPoint publicKeyPoint = ECCurve_secp256r1().curve.decodePoint([0x04, ...firstCert.publicKey])!;
    ECPublicKey ecPublicKey = ECPublicKey(publicKeyPoint, ECCurve_secp256r1());
    ECDSASigner verifier = ECDSASigner(SHA256Digest());
    verifier.init(false, PublicKeyParameter<ECPublicKey>(ecPublicKey));

    final r = BigInt.from(secondCert.signature.sublist(0, 32).buffer.asByteData().getUint64(0));
    final s = BigInt.from(secondCert.signature.sublist(32).buffer.asByteData().getUint64(0));
    final certSig = ECSignature(r,s);

    return verifier.verifySignature(secondCert.digest, certSig);
  }

Please ignore any typos (if any) and Certificate is just a class that determines which bytes pertain to what part of the Certificate.

dlewis2017 commented 1 year ago

Ended up being an issue unrelated to the library. I see there isn't a ECDSA example though so I'll leave this here but it can be closed.