Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to generate highly secured , fast random numbers  RSS feed

 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing an application in java but it seems to me that its performance of the speed at runtime is not so good. I just find out that generation of random numbers affect the performance so i am wondering which is the best way to generate random numbers from 0-255 in order to be faster and more secure by secure i mean random numbers to be highly random.
 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you generating random number now?

Why do you want them to be "highly random"?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never used it, but there is a SecureRandom class.
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That is the way how i am generating random numbers. It is ok but maybe any of you have any better idea how to generate it fast. I need highly secured because i need to develop a protocol which is based on Shamir Secret Sharing
 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It makes no sense to wrap SecureRandom in a class that generates one random byte at a time (in a broken way, I might add).

Just use SecureRandom directly wherever you need random bytes to generate the complete array of random bytes in one go.

 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Stephan Van Hulst the reason i wrap it is to make it more secure by putting "SHA1PRNG" Do you know what is SHA1?. I also used what you have written but it is not faster than my one and moreover for sure not higher secured
 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So? You can provide a SecureRandom instance in the constructor that uses the SHA1PRNG algorithm. There's no need to wrap it in another class.

Do you have any proof that my solution would be less secure in any way? If anything, messing around with cryptographic primitives is less secure, as evidenced by the fact that the generateByte() method you provided will only ever return the value 0.

Furthermore, if this entire thing is anything other than an assignment or a practice problem, I instead urge you to use well-known and proven cryptographic algorithms that are tailored to whatever you need done. Don't roll your own crypto. You WILL get it wrong. I'm not saying just you, but me as well, and people that are smarter than both of us combined.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!