Advertisement
Chiddix

Salt

Sep 10th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1.     /**
  2.      * Hashes a password with the specified amount of iterations of salt.
  3.      * @param iterations The amount of iterations to apply the salt.
  4.      * @param password The password being hashed.
  5.      * @param salt The salt being applied to the password.
  6.      * @return The hashed password.
  7.      * @throws NoSuchAlgorithmException If an exception is thrown.
  8.      * @throws UnsupportedEncodingException If an exception is thrown.
  9.      */
  10.     public static final byte[] getHash(final int iterations, final String password, final byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
  11.         final MessageDigest digest = MessageDigest.getInstance("SHA-1");
  12.         digest.reset();
  13.         digest.update(salt);
  14.         byte[] input = digest.digest(password.getBytes("UTF-8"));
  15.         for (int i = 0; i < iterations; i++) {
  16.             digest.reset();
  17.             input = digest.digest(input);
  18.         }
  19.         return input;
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement