Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > BOOK: Beginning Cryptography with Java
|
BOOK: Beginning Cryptography with Java
This is the forum to discuss the Wrox book Beginning Cryptography with Java by David Hook; ISBN: 9780764596339
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Cryptography with Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2011, 11:14 AM
Authorized User
 
Join Date: Jun 2011
Posts: 38
Thanks: 9
Thanked 0 Times in 0 Posts
Default java.security.SignatureException: java.lang.ArithmeticException?

When I'm verifying the signature, I'm getting the following exception,

Not sure what it means and why the exception is happening, I'm using the same latest code provided in the book examples. Could you highlight what could be wrong? I'm able to create the signature file, this part fails when it tries to verify the signature.

java.security.SignatureException: java.lang.ArithmeticException: BigInteger not invertible


Caused by:
java.lang.ArithmeticException: BigInteger not invertible.
at java.math.MutableBigInteger.modInverse(MutableBigI nteger.java:1239)
at java.math.MutableBigInteger.mutableModInverse(Muta bleBigInteger.java:1114)
at java.math.BigInteger.modInverse(BigInteger.java:20 23)
at org.bouncycastle.crypto.signers.DSASigner.verifySi gnature(Unknown Source)
at org.bouncycastle.jce.provider.JDKDSASigner.engineV erify(Unknown Source)
at java.security.Signature$Delegate.engineVerify(Sign ature.java:1194)
at java.security.Signature.verify(Signature.java:647)
 
Old July 11th, 2011, 06:13 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

Looking at it I'd say the key was invalid. You might need to check that all the numbers have gone in in the right order.

Regards,

David
The Following User Says Thank You to dgh For This Useful Post:
boy18nj (July 11th, 2011)
 
Old July 11th, 2011, 07:09 PM
Authorized User
 
Join Date: Jun 2011
Posts: 38
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Thanks David, You are correct the key was invalid. But the error message is not intuitive enough to say the key is invalid.

Is there any catch that signals the key may be invalid?
 
Old July 12th, 2011, 08:36 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

I'd say in this case the exception should probably be wrapped in a SignatureException. I'll add that to the BC jira. Having said that you could pass in an invalid key which won't cause an exception, just fail to verify the signature (at the end of the day, verification is just a series of big integer operations...) so this is really one of those places where you just have to be careful.

Regards,

David
The Following User Says Thank You to dgh For This Useful Post:
boy18nj (July 12th, 2011)
 
Old July 12th, 2011, 09:29 PM
Authorized User
 
Join Date: Jun 2011
Posts: 38
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Thanks. I was surprised to see, creation of signature worked fine with invalid key. But the verification of signature is throwing this exception. And chances of throwing exception 1 in 3 times.
 
Old July 12th, 2011, 10:05 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

Yep, that sounds about right. As I mentioned earlier, with BigInteger algorithms it all depends how the maths works out as to what happens if a key is wrong.

Regards,

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
Root Cause:java.lang.NoSuchMethodError: java.util. anees81 JSP Basics 3 March 1st, 2011 08:55 AM
java.lang.OutOfMemoryError: Java heap space meetkotresh J2EE 1 February 2nd, 2008 01:52 AM
java.lang.StackOverflowError ravi_sri24 XSLT 31 February 1st, 2008 09:48 AM
java.lang.ArrayIndexOutOfBoundsException chiraagb Pro JSP 1 July 1st, 2006 07:21 PM
java.lang.Runtime mudasirw J2EE 1 August 2nd, 2005 02:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.