Professional Documents
Culture Documents
Objectives
Exercises
KeyPairGenerator keyGen =
KeyPairGenerator.getInstance("RSA");
The next step is to initialize the key pair generator. All key
pair generators share the concepts of a keysize and a source
of randomness. A KeyPairGenerator class
initialize method has these two types of arguments.
Thus, to generate keys with a keysize of 1024 and a new
SecureRandom object seeded by the userSeed value
(e.g. userSeed = 123456789), you can use the
following code:
SecureRandom random =
SecureRandom.getInstance("SHA1PRNG","SUN");
random.setSeed(userSeed);
keyGen.initialize(1024, random);
The final step is generating the key pair. The following code
is used to generate the key pair:
KeyPair pair = keyGen.generateKeyPair();
Generating a Signature
Signature rsa =
Signature.getInstance("SHA1withRSA");
Next, using the key pair generated in the key pair example,
we initialize the object with the private key, and then sign a
byte array called data.
Verifying a Signature
BigInteger class
2 Exercises