Here you can find the source of getHash(int iterationNb, String password, byte[] salt)
Parameter | Description |
---|---|
iterationNb | int The number of iterations of the algorithm |
password | String The password to encrypt |
salt | byte[] The salt |
Parameter | Description |
---|---|
NoSuchAlgorithmException | If the algorithm doesn't exist |
private static byte[] getHash(int iterationNb, String password, byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//from ww w. j a v a 2s . c o m * From a password, a number of iterations and a salt, * returns the corresponding digest * @param iterationNb int The number of iterations of the algorithm * @param password String The password to encrypt * @param salt byte[] The salt * @return byte[] The digested password * @throws NoSuchAlgorithmException If the algorithm doesn't exist */ private static byte[] getHash(int iterationNb, String password, byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); digest.update(salt); byte[] input = digest.digest(password.getBytes("UTF-8")); for (int i = 0; i < iterationNb; i++) { digest.reset(); input = digest.digest(input); } return input; } }