salt-creation

Java - Generating a random salt isn't random

本秂侑毒 提交于 2019-12-08 23:40:36
问题 I'm trying to generate a salt in Java to use with a hashing algorithm for secure password storage. I'm using the following code to create the random salt: private static String getSalt() throws NoSuchAlgorithmException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] salt = new byte[16]; sr.nextBytes(salt); System.out.println(salt.toString()); return salt.toString(); } Which should generate a completely secure, randomly generated salt to use in my hashing algorithm. When I run

Java - Generating a random salt isn't random

放肆的年华 提交于 2019-11-30 10:58:19
I'm trying to generate a salt in Java to use with a hashing algorithm for secure password storage. I'm using the following code to create the random salt: private static String getSalt() throws NoSuchAlgorithmException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] salt = new byte[16]; sr.nextBytes(salt); System.out.println(salt.toString()); return salt.toString(); } Which should generate a completely secure, randomly generated salt to use in my hashing algorithm. When I run the code however, it keeps outputting the same salt every time... Indicating that the salt being

How to generate a random, long salt for use in hashing?

柔情痞子 提交于 2019-11-30 06:56:48
问题 What is a way in PHP to make a random, variable length salt for use in hashing? Let's say I want to make a 16-character long salt - how would I do it? 回答1: edit: the mcrypt extension has been deprecated. For new projects take a look at random_bytes ( int $length ) and the sodium (as of php 7.2 core-)extension. If the mcrypt extension is available you could simply use mcrypt_create_iv(size, source) to create a salt. $iv = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); var_dump($iv); Since each byte

How to generate a random, long salt for use in hashing?

爱⌒轻易说出口 提交于 2019-11-28 23:27:15
What is a way in PHP to make a random, variable length salt for use in hashing? Let's say I want to make a 16-character long salt - how would I do it? edit: the mcrypt extension has been deprecated. For new projects take a look at random_bytes ( int $length ) and the sodium (as of php 7.2 core-)extension. If the mcrypt extension is available you could simply use mcrypt_create_iv(size, source) to create a salt. $iv = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); var_dump($iv); Since each byte of the "string" can be in the range between 0-255 you need a binary-safe function to save/retrieve it.