∟JcaSign.java - Signature Generation Sample Program
This section provides tutorial example on how to write a digital signature generation sample program to sign any input data with a given private key.
The following program is a standalone program that reads in an input file and a private
key file, and generates a signature file based on the specified digital signature algorithm.
As you can see, this program also uses the KeyFactory class to read in the private key
stored in an encoded file, which can be generated by my other program, JcaKeyPair.java.
Here is result of my first test using DSA as the key generation algorithm,
and SHA1withDSA as the digital signature algorithm. It is done with JDK 1.3.1.
A pair of keys is generated using the DSA algorithm first. The private key is stored in
dsa.pri, and the public key in dsa.pub.
The private key is decoded from the file using the KeyFactory class in PKCS#8 format.
Then a signature is generated for input file, JcaSign.class, using
the SHA1withDSA algorithm, which uses SHA-1 for the message digest generation, and
DSA for encryption.
The signature is stored in JcaSign_dsa.sgn.
Now try it with the RSA key generation algorithm. You should have no problem at all.