Fisher
Fisher

Reputation: 11

Linux/Java - Change Seed Source of SecureRandom

I have the following SecureRandom implementation:

public static int getSecureRandomInt(int min, int max) {

    int random = -1;

    try {

        SecureRandom secureRandom = SecureRandom.getInstance("NativePRNG");

        byte[] bytes = new byte[512];
        secureRandom.nextBytes(bytes);

        random = secureRandom.nextInt(max);

        while(random < min) {

            bytes = new byte[512];
            secureRandom.nextBytes(bytes);

            random = secureRandom.nextInt(max);

        }

    } catch (NoSuchAlgorithmException noSuchAlgo) {

        System.out.println(" No Such Algorithm exists " + noSuchAlgo);

    }

    return random;

}

I now want that the destinantion of the seed is /dev/ttyACM1 (my Hardware RNG) and not /dev/random or /dev/urandom/. I already tried to edit the java.security file and set it via

securerandom.source=file:/dev/ttyACM1

but that has somehow no effect. I would prefer to make a permamnent link from /dev/random and /dev/urandom to /dev/ttyACM1 permanently so that every application that uses this two locations for getting entropy uses automatically my Hardware RNG. My OS is Ubuntu 15.04.

Thank you for your support :)

Upvotes: 1

Views: 624

Answers (1)

Peter O.
Peter O.

Reputation: 32878

You can use SecureRandom's setSeed method to supplement the "randomness" used by SecureRandom with arbitrary data, including data from /dev/urandom or some other nondeterministic source.

Upvotes: 1

Related Questions