javarandomkey-pairsecure-random

How to use external random number generator with java.security.KeyPairGenerator?


Basically I have a RNG providing random numbers into a database and I would like to use these random numbers when generating a key pair.

From my understanding so far, you can initialize the KeyPairGenerator providing a randomness source (SecureRandom object). Looking into SecureRandom documentation, I only see the possibility to provide a seed that will be used as a "base" seed when generating a seed (method generateSeed()). Am I correct ?

Do I have to create my own implementation of SecureRandomSpi class where the generateSeed() method would basically return a random number picked from the database ?

I would appreciate advices from someone with experience in this matter.

Thank you for your support.


Solution

  • I believe you can just subclass SecureRandom since it has an accessible no-args constructor. You should look at the source code for the bouncycastle library classes in package org.bouncycastle.crypto.prng, in particular the FixedSecureRandom class, for examples.