Deterministic Generation of RSA Encryption Key Pairs

I am trying to deterministically generate an RSA key pair using Java on Android. My requirements are that I cannot save a key pair, and it must be generated at runtime in order to be equivalent to previous / future runs.

My process was that I would deterministically run a random number generator and pass this generator to create the keys. My code is:

SecureRandom random=SecureRandom.getInstance("SHA1PRNG");
random.setSeed(1234);   //something device specific will be used to set this
KeyPairGenerator keyGen=KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024, random);

KeyPair pair=keyGen.generateKeyPair();
PublicKey pub=pair.getPublic();
PrivateKey priv=pair.getPrivate();

The resulting keys are different from the run to run. However, SecureRandom numbers are the same for startup, and even for all devices.

What am I missing? How can I repeat these keys?

thank

+3
source share
1 answer

? , SHA1PRNG Android, . , setSeed() , , , SecureRandom . Java, , . (?) Android, .

, . , API KeyChain ICS ICS. , - , (), , , . , , .

, , RSA BigIntegers , . , , . , SpongyCastle, RSAKeyPairGenerator.java, , .

+8

All Articles