Previous | Next | Trail Map | Security in JDK 1.1 | Using the Security API to Generate and Verify a Signature

Step 1: Prepare Initial Program Structure

To start the creation of our example application:
  1. Create a text file named testSig.java.

  2. Add import statements.

    The methods for signing data are in the java.security package, so we import everything from that package. We also need to import the java.io package since it contains the methods we need to input the file data to be signed.

    import java.io.*;
    import java.security.*;
    
  3. Start the class definition:
    class testSig {
    
  4. Type the signature for the main method (which we need, since this is an application), and write a comment about what this program does:
        public static void main(String[] args) {
    
            /* Test generating and verifying a DSA signature */
    
  5. Write the exception-handling blocks.

    These are needed because many methods called by the program throw exceptions that we must catch. Note: The code we write in subsequent steps of this lesson to generate and verify a signature will go between the try and catch blocks.

            try {
    
    
    
            } catch (Exception e) {
                System.err.println("Caught exception " + e.toString());
            }
    
    
  6. Write the closing braces for the main method and the testSig class:
        }
    
    }
    
    

What We've Got So Far

Now we've got the basic structure of our program. It looks like this:

import java.io.*;
import java.security.*;

class testSig {

    public static void main(String[] args) {

        /* Test generating and verifying a DSA signature */

        try {



        } catch (Exception e) {
            System.err.println("Caught exception " + e.toString());
        }
    }

}


Previous | Next | Trail Map | Security in JDK 1.1 | Using the Security API to Generate and Verify a Signature