Questions tagged [secure-random]

SecureRandom is a Java class that provides a cryptographically strong random number generator (RNG).

SecureRandom is a Java class that provides a cryptographically strong random number generator (RNG).

A cryptographically strong random number minimally complies with the statistical random number generator tests specified in FIPS 140-2, Security Requirements for Cryptographic Modules, section 4.9.1. Additionally, SecureRandom must produce non-deterministic output. Therefore any seed material passed to a SecureRandom object must be unpredictable, and all SecureRandom output sequences must be cryptographically strong, as described in RFC 1750: Randomness Recommendations for Security.

http://docs.oracle.com/javase/7/docs/api/java/security/SecureRandom.html

84 questions
29
votes
2 answers

How to generate a SecureRandom string of length n in Java?

I'm generating a random string using: private String generateSafeToken() { SecureRandom random = new SecureRandom(); byte bytes[] = new byte[512]; random.nextBytes(bytes); return bytes.toString(); } This gives a string of length 11…
kovac
  • 4,945
  • 9
  • 47
  • 90
26
votes
4 answers

UUID.randomUUID() vs SecureRandom

I am trying to understand the advantages of using UUID.randomUUID() over SecureRandom generator as the former uses securerandom internally.
User3518958
  • 676
  • 1
  • 6
  • 19
15
votes
3 answers

Does the Android implementation of SecureRandom produce true random numbers?

I have read that, generally, some implementations of SecureRandom may produce true random numbers. In particular, the Android docs say instances of this class will generate an initial seed using an internal entropy source, such as /dev/urandom but…
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
9
votes
2 answers

Reusing java.util.Random instance vs creating a new instance every time

The title pretty much summarizes it - we can create one instance of java.util.Random (or SecureRandom) and use it every time we need a random value or we can create a new instance every time on demand. Wondering which one is the preferred way and…
khachik
  • 28,112
  • 9
  • 59
  • 94
9
votes
1 answer

Java: How do I set the nonce when using DRBG SecureRandom?

Java 9 introduced a new SecureRandom called DRBG. I want to use it to deterministically generate random numbers. The problem is that it uses a nonce internally which it always changes, so I don't get the same numbers for the same seeds. It does have…
Lazar Petrovic
  • 537
  • 3
  • 8
8
votes
2 answers

What's the best way to create a "good" SecureRandom?

There are a lot of questions asking if a specific initiation of SecureRandom is "good", but I couldn't find a rule of thumb. What's the best way to create a "good" random SecureRandom? // Fast // Is it a good random? SecureRandom secureRandom = new…
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
8
votes
3 answers

SecureRandom provider "Crypto" unavailable in Android N for deterministially generating a key

Users can purchase a "Pro" version of my app. When they do, I store and verify their purchase as follows. Combine the user's UUID and another unique string. The resulting string is then encrypted using a static seed. I do this using…
NSouth
  • 5,067
  • 7
  • 48
  • 83
7
votes
4 answers

Generating random number of length 6 with SecureRandom in Ruby

I tried SecureRandom.random_number(9**6) but it sometimes returns 5 and sometimes 6 numbers. I'd want it to be a length of 6 consistently. I would also prefer it in the format like SecureRandom.random_number(9**6) without using syntax like…
gogofan
  • 533
  • 1
  • 10
  • 20
6
votes
1 answer

SecureRandom is unreasonably slow or freezes the system

A java application does something like this: SecureRandom random = new SecureRandom(); for(int i=0;i<12;i++){ random.nextInt(19); } At random.nextInt() the java freezes for several minutes, seems it hangs indefinitely. The weird part is that the…
Micó Papp
  • 301
  • 2
  • 7
4
votes
1 answer

Should I initialize the SecureRandom for my BCryptPasswordEncoder with a seed?

I am just doing a code review of a co-workers task and came across the following lines of code (he was implementing a Spring Security based login system). @Bean public PasswordEncoder passwordEncoder(){ return new…
Tim
  • 409
  • 1
  • 6
  • 15
3
votes
1 answer

SecureRandom stream weird behavior with multiple threads

I'm trying to generate random values using SecureRandom, specifically its support of streams. Ideally the values should be generated on a constant basis, so the stream could be infinite: SecureRandom secureRandom = new…
M A
  • 71,713
  • 13
  • 134
  • 174
3
votes
0 answers

Java /dev/urandom configuration

Whenever I look up switching Java to using /dev/urandom from /dev/random most sources mention it should be specified as /dev/./urandom as a workaround for a bug in Java. I wonder if this still necessary for Java 8 and up. Bug description references…
oᴉɹǝɥɔ
  • 1,796
  • 1
  • 18
  • 31
3
votes
2 answers

Where can I get a reliable source of entropy (real randomness byte[])?

Currently, I'm looking for a way to increase the quality of randomness in my Android application (a card game). Previously, it was estimated that for my situation (52! permutation) at least 226 bits of entropy (226 random bits) are needed.. I'm…
Sergey Emeliyanov
  • 5,158
  • 6
  • 29
  • 52
3
votes
1 answer

How to generate all possible 64 bit random values in java?

Does Java SecureRandom.nextLong() return all possible values given it inherits from Random which uses only 48 bits? If not, can I still do it in Java maybe by modifying the Random class and how to do it? I just want to use an all random long number…
mj1261829
  • 1,200
  • 3
  • 26
  • 53
3
votes
2 answers

Should I periodically reSeed SecureRandom or it occurs automatically?

We are using SecureRandom as follows (using Java8): import java.security.SecureRandom; private SecureRandom random = new SecureRandom(); The algorithm being used is NativePRNG. Should we seed periodically? as it's written that NativePRNG is…
rayman
  • 20,786
  • 45
  • 148
  • 246
1
2 3 4 5 6