0
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class Main {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        SecureRandom srand = SecureRandom.getInstance("NativePRNG");
        System.out.println(srand.nextInt());
    }
}

How to run with NativePRNG on windows?

UPD: By default, in Java 10+, \<JDK>\conf\security\java.security file, crypto.policy=unlimited. sp nothing need to be changed for Java 10+ in java.security file. And to use NativePRNG algorithm, we can change it to Windows-PRNG.

SecureRandom srand = SecureRandom.getInstance("Windows-PRNG");
System.out.println(srand.nextInt());
Bhaskar13
  • 191
  • 4
  • 14

1 Answers1

0

The reason the code fails on Windows is because the "NativePRNG" algorithm is not available on all platforms, including Windows. This is because "NativePRNG" relies on platform-specific sources of randomness, and the implementation may vary across different operating systems.

To run with "NativePRNG" on Windows, you can install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files, which includes a "NativePRNG" implementation for Windows. Once you have installed the JCE Unlimited Strength Policy Files, you can modify the code to explicitly specify the "NativePRNG" algorithm provider:

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class Main {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        SecureRandom srand = SecureRandom.getInstance("NativePRNG", "SUN");
        System.out.println(srand.nextInt());
    }
}

Note that you should replace "SUN" with the name of the provider that supports the "NativePRNG" algorithm on your specific platform, as different providers may support different algorithms on different platforms.

K2J
  • 2,573
  • 6
  • 27
  • 34