Two salt Values?
-
I'm getting two values for my salt This is my code
private static String getSalt() throws NoSuchAlgorithmException, NoSuchProviderException
{
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
//SecureRandom sr = new SecureRandom();
byte[] salt = new byte[8192];
sr.nextBytes(salt);
return salt.toString();}
and when I save it in my database my code
PS.setString(1, User);
PS.setString(2, getSalt());
PS.executeUpdate();
System.out.println(" Salt :"+getSalt());I get different value..why? I'm salting String asdf
Database value [B@2fc396df
Printed value [B@5199c9ac -
I'm getting two values for my salt This is my code
private static String getSalt() throws NoSuchAlgorithmException, NoSuchProviderException
{
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
//SecureRandom sr = new SecureRandom();
byte[] salt = new byte[8192];
sr.nextBytes(salt);
return salt.toString();}
and when I save it in my database my code
PS.setString(1, User);
PS.setString(2, getSalt());
PS.executeUpdate();
System.out.println(" Salt :"+getSalt());I get different value..why? I'm salting String asdf
Database value [B@2fc396df
Printed value [B@5199c9ac -
I'm getting two values for my salt This is my code
private static String getSalt() throws NoSuchAlgorithmException, NoSuchProviderException
{
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
//SecureRandom sr = new SecureRandom();
byte[] salt = new byte[8192];
sr.nextBytes(salt);
return salt.toString();}
and when I save it in my database my code
PS.setString(1, User);
PS.setString(2, getSalt());
PS.executeUpdate();
System.out.println(" Salt :"+getSalt());I get different value..why? I'm salting String asdf
Database value [B@2fc396df
Printed value [B@5199c9acBy the way, your function createSalt() creates a new salt every time you call it! When you want to compare the original value and the database value, you hat to write the salt into a variable, then set it to your object, write to database, then retrieve from the database.