Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Hashes a password with the specified amount of iterations of salt.
- * @param iterations The amount of iterations to apply the salt.
- * @param password The password being hashed.
- * @param salt The salt being applied to the password.
- * @return The hashed password.
- * @throws NoSuchAlgorithmException If an exception is thrown.
- * @throws UnsupportedEncodingException If an exception is thrown.
- */
- public static final byte[] getHash(final int iterations, final String password, final byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
- final MessageDigest digest = MessageDigest.getInstance("SHA-1");
- digest.reset();
- digest.update(salt);
- byte[] input = digest.digest(password.getBytes("UTF-8"));
- for (int i = 0; i < iterations; i++) {
- digest.reset();
- input = digest.digest(input);
- }
- return input;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement