java - Verify ECDSA signature using SpongyCastle -


i'm trying verify ecdsa digital signature on android using spongycastle. have x509certificate contains public key need use verify can't quite figure out how publickey (down cast ecpublickey) use ecdsasigner class.

i've done using c# version of bouncycastle looks this:

ecdsasigner signer = new ecdsasigner(); signer.init(false, cert.getpublikey()); 

in java version of apis, x509certificate.getpublickey() method returns publickey class instead of asymmetrickeyparameter. however, ecdsasigner.init() method needs cipherparameters object. can't figure out how ecdsa.

for rsa signatures manually reconstructed new rsakeyparameters object:

rsaengine engine = new rsaengine(); engine.init(     false,     new rsakeyparameters(         false,         ((rsapublickey) pubkey).getmodulus(),         ((rsapublickey) pubkey).getpublicexponent()     ) ); 

this doesn't seem ideal think should work. can't figure out how equivalent ecdsa. think there's better way can't figure out right apis use.

i think figured out. looks need use signature class handle instead of using ecdsasigner class directly. i'd still understand how ecdsasigner class used internally inside of abstraction (just own curiosity).

anyways, code looks verify ecdsa signature (for use @ least). future person trying solve similar issue:

signature sig = signature.getinstance("nonewithecdsa", "bc"); sig.initverify(pubkey); sig.update(plainbytes); if (!sig.verify(signedbytes)) {     throw new exception("ecdsa signature verification failed."); } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -