I have a problem with generating public key for RSA in java. I use KeyPairGenerator and I get public, private key, p, q and modulus. It is fine. But everytime public key is a 65537. Is there any posibility to generate different public key each time?
Code:
KeyPair keys;
KeyPairGenerator generator;
try {
generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(1024);
keys = generator.genKeyPair();
} catch (NoSuchAlgorithmException ex) {}
The public key can’t be simply 65537, since in RSA a public key is a pair (n,e) where n is the modulus and e is the exponent. Typically, the exponent is equal to 65537, and it is the modulus that changes.
So, in order to make sure you are generating different keys every time, check that the modulus is changing.