Can you set the overall RSA to a value of your choice?

This website describes a way to implement RSA in java using a library. Is it possible to have control over the value of the public indicator e? Java sets it to 65537. I know this is a good value, but can I change it while still using the library?

This is how they implement it:

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),
RSAPublicKeySpec.class);
RSAPrivateKeySpec priv = fact.getKeySpec(kp.getPrivate(),
RSAPrivateKeySpec.class);

saveToFile("public.key", pub.getModulus(),
pub.getPublicExponent());
saveToFile("private.key", priv.getModulus(),
priv.getPrivateExponent());

      

+3


source to share


1 answer


Yes, you can, but you must be sure that this is a prime number (limited by the module size):

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
// 17 is another often used value, beware to use proper RSA padding if you set it to 3
RSAKeyGenParameterSpec kpgSpec = new RSAKeyGenParameterSpec(2048, BigInteger.valueOf(3));
kpg.initialize(kpgSpec);
KeyPair kp = kpg.genKeyPair();

      



Please note that you cannot change it after the key has been generated. Also note that if your exponent is too large (or has many bits set to 1), this will affect the speed of public key operations. 65537 - The default is a good value that only has 2 bits equal to 1 (the fourth Fermat number or F4).

+1


source







All Articles