SHA-256 패스워드 생성

Program_Language/Java 2012. 4. 4. 14:18 Posted by Request

/**
     * 입력된 password 로 SHA-256 hashCode 생성.
     * @return byte[]
     */
    public 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;
    }