File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark ""java.security.SignatureException: invalid encoding for signature" when following the Java Tutorial" Watch ""java.security.SignatureException: invalid encoding for signature" when following the Java Tutorial" New topic
Author

"java.security.SignatureException: invalid encoding for signature" when following the Java Tutorial

Chris Lorenz
Greenhorn

Joined: Apr 10, 2013
Posts: 1
I am following the Java tutorial at:
http://docs.oracle.com/javase/tutorial/security/apisign/enhancements.html

It concerns programmatically extracting a private key from a keystore as well as the matching certificate on the sender side, then generating a signature with the private key and finally saving both cerificate and signature in a file each.
On the receiver's side the cerificate file is read in programmatically as well as the signature file, the public key is extracted from the certificate and finally used to programmatically verify the signature.

The tutorial doesn't print the full code for this. Instead, it merely prints some (plausible looking) snippets that the reader is supposed to use to modify the classes GenSig.java and VerSig.java that were provided in the preceding chapters of this lesson.

I followed these suggestions, modified both files to work in principle. I used the keystore and the keypair+certificate that was created while following the earlier part of this tutorial trail starting at
http://docs.oracle.com/javase/tutorial/security/toolsign/index.html

In short, I completely stayed within java tutorial material.
Still, when running my new and enhanced class VerSigWithCertificate.java after running my new and enhanced class GenSigWithCertificate.java I get the above mentioned "java.security.SignatureException: invalid encoding for signature" .

What am I missing?
Can anyone provide concrete code alterations to make it work?
As you can see, I hard coded some necessary infos into the code. Removing them will be my next step after the main problem is solved.
Thank you!

The code for both classes is as follows:
class GenSigWithCertificate.java:



class VerSigWithCertificate.java:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "java.security.SignatureException: invalid encoding for signature" when following the Java Tutorial
 
Similar Threads
Java security and SSO question
unable to read key values from file
DSA - Signature failed
using bouncy castle jce provider??
Return Token with Private/Public keys