Download the JDK
Search the Tutorials
Hide the TOC
Trail: Security Features in Java SE
Lesson: Generating and Verifying Signatures
Section: Generating a Digital Signature
Generating and Verifying Signatures
Generating a Digital Signature
Prepare Initial Program Structure
Generate Public and Private Keys
Sign the Data
Save the Signature and the Public Key in Files
Compile and Run the Program
Verifying a Digital Signature
Prepare Initial Program Structure
Input and Convert the Encoded Public Key Bytes
Input the Signature Bytes
Verify the Signature
Compile and Run the Program
Weaknesses and Alternatives
Home Page > Security Features in Java SE > Generating and Verifying Signatures
Compile and Run the Program

> `Here` is the complete source code for the `GenSig.java` program, with some comments added. Compile and run it. Remember, you need to specify the name of a file to be signed, as in

> >     java GenSig data

> You can download and use this sample file named `data` or any other file you like. The file will not be modified. It will be read so that a signature can be generated for it.

> After executing the program, you should see the saved `suepk` (public key) and `sig` (signature) files.

Previous page: Save the Signature and the Public Key in Files
Next page: Verifying a Digital Signature