I'm converting some C# code to Java. I can't find an equivalent to RNGCryptoServiceProvider
. How do I do this?
private static String GetRandomSalt()
{
RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();
byte[] salt = new byte[32]; //256 bits
random.GetBytes(salt);
...
}
To expand on my comment:
Java's SecureRandom
is the equivalent you're looking for.
SecureRandom random = new SecureRandom();
byte[] salt = new byte[32];
random.nextBytes(salt);
The documentation details some other ways to get an instance of SecureRandom
, depending on your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With