Skip to content

Commit f87cf5a

Browse files
Add thread local secure random
1 parent 89d864e commit f87cf5a

File tree

1 file changed

+28
-0
lines changed
  • src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/internal

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.amazonaws.services.dynamodbv2.datamodeling.internal;
2+
3+
import java.security.SecureRandom;
4+
5+
public class Utils {
6+
private static final ThreadLocal<SecureRandom> RND = new ThreadLocal<SecureRandom>() {
7+
@Override
8+
protected SecureRandom initialValue() {
9+
final SecureRandom result = new SecureRandom();
10+
result.nextBoolean(); // Force seeding
11+
return result;
12+
}
13+
};
14+
15+
private Utils() {
16+
// Prevent instantiation
17+
}
18+
19+
public static SecureRandom getRng() {
20+
return RND.get();
21+
}
22+
23+
public static byte[] getRandom(int len) {
24+
final byte[] result = new byte[len];
25+
getRng().nextBytes(result);
26+
return result;
27+
}
28+
}

0 commit comments

Comments
 (0)