|
March 06, 2011, 10:21:55 AM |
|
Hey,
So you said you wouldn't mind answering any question regarding this-
So I've been working on a project and I need to verify a signature, given to me.
When I both generate & verify the signature, everything works perfectly, but when I'm trying to verify the other guy's signature it crushes saying: "error decoding signature bytes.", specifically I found out it crushes here: ASN1InputStream aIn = new ASN1InputStream(signature.getBytes()); try { ASN1Sequence s = (ASN1Sequence)aIn.readObject();/*crushes on this line exactly...*/ } catch (IOException e) {
}
I attached the functions related...
private PublicKey generatePublicKey(Point pPublicKey, String sCurve) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, InvalidAlgorithmParameterException { X9ECParameters ecParams = NISTNamedCurves.getByName(sCurve); ECPoint pPublicPoint = ecParams.getCurve().createPoint(pPublicKey.x, pPublicKey.y, false); ECParameterSpec spec = new ECParameterSpec(ecParams.getCurve(), ecParams.getG(), ecParams.getN()); ECPublicKeySpec publicSpec = new ECPublicKeySpec(pPublicPoint, spec); KeyFactory keyfac = KeyFactory.getInstance("ECDSA", "LOCAL_BC"); return keyfac.generatePublic(publicSpec); }
public ECDSAVerifier(Point pKey, String sHash, String sCurve) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, IOException, InvalidAlgorithmParameterException { this.key = generatePublicKey(pKey, sCurve); this.hashName = sHash; ECDSAGenerateVerifier(); }
private void ECDSAGenerateVerifier() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException { this.verifier = Signature.getInstance(this.hashName, "LOCAL_BC"); this.verifier.initVerify(this.key); }
public Boolean verify(byte[] message, byte[] signature) throws SignatureException, InvalidKeyException { this.verifier.update(message); return this.verifier.verify(signature); /*the code crushes here...*/ }
|