The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
The GenSig
program you are about to create will use the JDK Security API to generate keys and a digital signature for data using the private key and to export the public key and the signature to files. The application gets the data file name from the command line.
The following steps create the GenSig
sample program.
Prepare Initial Program Structure
Create a text file named GenSig.java
. Type in the initial program structure (import statements, class name, main
method, and so on).
Generate Public and Private Keys
Generate a key pair (public key and private key). The private key is needed for signing the data. The public key will be used by the VerSig
program for verifying the signature.
Get a Signature
object and initialize it for signing. Supply it with the data to be signed, and generate the signature.
Save the Signature and the Public Key in Files
Save the signature bytes in one file and the public key bytes in another.