Solved

# Generating RSA keys and doing RSA encryption (use Java Cryptix provider)

Posted on 2000-03-25

Hi friends,

I would like to generate pair of keys using the RSA algorithm in cryptix toolkit. However got a prob, Could you pls give some advices? Thank you very much.

Below is the code I used to generate the key pair:

import java.security.*;

import cryptix.provider.*;

import cryptix.provider.rsa.*;

import java.io.*;

class GenKey {

public static void main(String[] args)

{

KeyPairGenerator keys = null;

try{

keys = KeyPairGenerator.getInstance("RSA");

}

catch(NoSuchAlgorithmException e){

System.err.println(e);

}

((BaseRSAKeyPairGenerator)keys).initialize(1024,new SecureRandom());

KeyPair pair = keys.generateKeyPair();

System.out.println(pair.getPublic().toString());

System.out.println(pair.getPrivate().toString());

}

}

Output:

<--------RSAPublicKey:

n:Multi-Precision Integer 1024 bits long...

sign:Positive

magnitude:Hexadecimal dump of 128

bytes....

0 : 9d.....

32: 0D.....

64: AD....

96: 94...

e:Multi-Precision

sign:Positive

Magnitude:010001

--->

<BaseRSAPrivateKey>

From the output, it seem that NO private key is generated, only the public key is generated. Does I done anything wrong? Or the cryptix library cannot generate the private key?

As I need both the keys to do encryption and decryption, could you pls give some advice on using RSA encryption using Cryptix, since Java JCE is not exportable and the exportable JCE do not have the RSA algorithm?

Thank you very much...

regards HuangJo