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
1
vote
2 answers

Why does the BigInteger.isProbablePrime() function in Java return true for negative numbers?

I am implementing the RSA public-key cryptographic algorithm in Java. It requires generating two random prime numbers. I have been using the SecureRandom class to generate two 1024 bit numbers to create a 2048 bit key. I handle the numbers using the…
user7187118
1
vote
3 answers

Generate Random String in java

I'm trying to generate a string between capital A-Z in java using Secure Random. Currently I'm able to generate an alphanumeric string with special characters but I want a string with only upper case alphabets. public String createRandomCode(int…
Lucy
  • 1,812
  • 15
  • 55
  • 93
1
vote
2 answers

Generating random numbers in a particular range

I am trying to generate n random numbers between 0-31 in my Android code. Below is the code that I am using: int max_range = 31; SecureRandom secureRandom = new SecureRandom(); int[] digestCodeIndicesArr = new int[indices_length]; int i = 0,…
Sid
  • 1,224
  • 3
  • 23
  • 48
1
vote
3 answers

How to create a random output of a certain bit size in Java?

I want to create a random alpha-numeric string whose bit count will always be of size k. The size k will be something relatively big (varying from 128 to 2048 or more). I'm reading this excellent thread and I'm trying to figure something out using…
Aventinus
  • 1,322
  • 2
  • 15
  • 33
1
vote
3 answers

Is it guaranteed that 2 sequential calls to secure random will give different numbers?

Using SecureRandom is there a guarantee that 2 sequential calls will not return the same number? If this is a strict requirement from client API side, is the following loop in the code redundant or not? Random random =…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
0
votes
1 answer

How to properly use SecureRandom 12 digit number?

I am trying to create a random number use SecureRandom. It must be digits only (0123456789) and be 12 characters long. Any help would be greatly appreciated. SecureRandom secureRandom = new SecureRandom(); synchronized (secureRandom) { …
newPHPDev
  • 33
  • 5
0
votes
0 answers

How to implement RSA based on custom user defined padding -JAVA

Im trying to implement RSA based on custom padding value. cipher.init(ENCRYPT_MODE, publicKey,oaepParameter, secureRandom); I would like to change the secureRandom function to somthing else. Basically like to feed custom defined byte[] (could be…
DAN
  • 15
  • 1
  • 4
0
votes
1 answer

How to use SecureRandom instead of using hardcoded bytes array for Java AES Encrytion and Decryption?

In my code I am using hardcoded arrays(given below) for IV and key **private static byte[] IVAes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; private static byte[] keyAes = { 0x01, 0x02,…
Pragya S
  • 17
  • 2
0
votes
0 answers

how much reliable the Unique Id generated using SecureRandom

I need to obtain unique primary which is less than 24 char length, I have tried using SecureRandom and i read its documentation says A cryptographically strong random number. is this Reliable ? all I need to have Alphanumeric with max of 24 char…
jcrshankar
  • 1,165
  • 8
  • 25
  • 45
0
votes
0 answers

RandomUUID in UUID operators code explanation

I'm looking to understand the following operators &= 0x0f /* clear version */ |= 0x40 /* set to version 4 */ &= 0x3f /* clear variant */ |= 0x80. /* set to IETF variant */ Found in the following code UUID native java…
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
0
votes
1 answer

Java SecureRandom Instance SHA1PRNG equivalent in Node.JS/

I need to translate a function in Java to Node JS public byte[] GetId() throws NoSuchAlgorithmException { byte[] byArray = new byte[4]; byte[] byArray2 = new byte[8]; SecureRandom secureRandom =…
0
votes
1 answer

How to access SecureRandom in jsbn typescript?

I used to access the SecureRandom in jsbn.js this way var jsbn = require('jsbn'); var SecureRandom = jsbn.SecureRandom; var secureRandom = new SecureRandom(); secureRandom.nextBytes(x); How do I access it in jsbn.ts? As there seem to be limited…
Sithideth Bouasavanh
  • 1,011
  • 1
  • 11
  • 20
0
votes
0 answers

SecureRandom is not working as expected in docker adoptopenjdk-tomcat image

I am using docker image of tomcat to run the application. The image details are: tomcat:9.0.45-jdk11-adoptopenjdk-hotspot. When I run the application on my local machine where I have jdk11-adoptopenjdk installed the application working fine but same…
Atul
  • 3,043
  • 27
  • 39
0
votes
1 answer

Generating unique random values with SecureRandom

i'm currently implementing a secret sharing scheme.(shamir) In order to generate some secret shares, I need to generate some random numbers within a range. FOr this purpose, I have this very simple code: val sharesPRG = SecureRandom() fun…
crypto_confuse
  • 463
  • 1
  • 4
  • 9
0
votes
2 answers

How to generate a SecureRandom number with a specific bit range

I have maximum number of bits that is not bit aligned E.g. 35 and required to generate unique random number from 1 - 68719476734 (max number for 35 bits). Could use SecureRandom but will have to extract 5 bytes out of it and convert to Long maybe,…
user964287
  • 713
  • 1
  • 7
  • 11