secure-random

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

自闭症网瘾萝莉.ら 提交于 2019-12-08 16:14:58
问题 This question already has answers here : How to generate a random alpha-numeric string? (41 answers) Closed last year . 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 such as [B@70ffc557 . How can I make this above method return a string of a specified length. For example 20 characters? 回答1: I don't understand

What actual algorithm is used by SecureRandom.getInstance(“DRBG”)?

谁都会走 提交于 2019-12-08 05:39:28
Java 9 (JSR 379) introduces the NIST DRBG's as specified in JEP 273 . However, the NIST document SP 800-90Ar1 (NIST Special Publication 800-90A Revision 1: Recommendation for Random Number Generation Using Deterministic Random Bit Generators) specifies a total of tree mechanisms: Implement the three DRBG mechanisms (Hash_DRBG, HMAC_DRBG, CTR_DRBG) in 800-90Ar1 (on all platforms). However, although you might expect that we would now have three methods to create such secure random algorithms: SecureRandom.getInstance("Hash_DRBG") SecureRandom.getInstance("HMAC_DRBG") SecureRandom.getInstance(

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

亡梦爱人 提交于 2019-12-08 02:01:25
问题 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 planning to use this byte[] as a seed for SecureRandom : SecureRandom random = new SecureRandom(); random.setSeed(/* insert seed here, byte[] */) The question is -- Where can I reliably get random bits in this amount (at least 226 bits) on Android ,

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

情到浓时终转凉″ 提交于 2019-12-06 08:10:58
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 planning to use this byte[] as a seed for SecureRandom : SecureRandom random = new SecureRandom(); random.setSeed(/* insert seed here, byte[] */) The question is -- Where can I reliably get random bits in this amount (at least 226 bits) on Android , preferably without requiring any permissions and without internet. Also, it should work regardless of

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

北城余情 提交于 2019-11-29 04:22:30
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 SecureRandom.getInstance("SHA1PRNG", "Crypto") - This is the problem! The resulting encrypted string is then the "unlock code". Therefore, I always know the expected unique unlock code value for the user. When the user purchases "Pro", I store the "unlock code" in the database. I check to see whether the user has "Pro" by seeing if the stored "unlock code" in the

How to get a random number in Ruby

◇◆丶佛笑我妖孽 提交于 2019-11-26 05:31:47
How do I generate a random number between 0 and n ? VonC Use rand(range) From Ruby Random Numbers : If you needed a random integer to simulate a roll of a six-sided die, you'd use: 1 + rand(6) . A roll in craps could be simulated with 2 + rand(6) + rand(6) . Finally, if you just need a random float, just call rand with no arguments. As Marc-André Lafortune mentions in his answer below (go upvote it) , Ruby 1.9.2 has its own Random class (that Marc-André himself helped to debug , hence the 1.9.2 target for that feature). For instance, in this game where you need to guess 10 numbers , you can