Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Two salt Values?

Two salt Values?

Scheduled Pinned Locked Moved Java
databasequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chdboy
    wrote on last edited by
    #1

    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

    J B 2 Replies Last reply
    0
    • C chdboy

      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

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      salt.toString();

      That doesn't do what you think it does. It prints the object reference not the contents.

      1 Reply Last reply
      0
      • C chdboy

        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

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        By 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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups