ECDSA Public Key Encoding Problem (BouncyCastle)
843810Mar 19 2003 — edited Mar 24 2003<This was cross-posted to the dev-crypto@bouncycastle.org list>
I'm trying to verify an ECDSA signature but unfortunately, I get an error when encoding then decoding ECDSA public keys (using BouncyCastle with JDK 1.4.1).
When I run the following code on the original key and then after encoding and decoding (I put it on an X509V3Certificate):
if (new String(decodedPubKey.getEncoded()).equals(new String pubKey.getEncoded()))) {
System.out.println("MATCHES");
} else {
System.out.println("TROUBLE");
}
It comes up with MATCHED but the hashcodes are different and when I print out the string representations with the toString() method I get:
Decoded toString: algorithm = 1.2.840.10045.2.1, params unparsed, unparsed keybits =
0000: 02 00 94 02 C1 7B 3D 7F 8E 94 1F 90 EF 2E F2 4B ......=........K
0010: 1E 81 0A 73 3D 74 27 5F ED 30 ...s=t'_.0
Original toString: EC Public Key
X: 9402c17b3d7f8e941f90ef2ef24b1e810a733d74275fed30
Y: 63b8f502764ddcadda9f603925da562954e5a85bd274bd37
Both original and decoded public keys report being X.509 format. I can encode and decode RSA and DSA keys just fine. The reason I found this problem was that I got an error message:
java.security.InvalidKeyException: can't identify DSA public key.
at org.bouncycastle.jce.provider.DSAUtil.generatePublicKeyParameter(DSAUtil.java:30)
at org.bouncycastle.jce.provider.JDKDSASigner.engineInitVerify(JDKDSASigner.java:52)
at java.security.Signature.initVerify(Signature.java:297)
at Test4.main(Test4.java:48)
Since the key is not DSA (but ECDSA) it shouldn't use DSA classes anyways (the OID reported is that of ECDSA).
Any thoughts or help would be appreciated,
- Doug