Java Digest digest(String value, byte[] salt, int iterations)

Here you can find the source of digest(String value, byte[] salt, int iterations)

Description

digest

License

Open Source License

Declaration

public static byte[] digest(String value, byte[] salt, int iterations)
            throws NoSuchAlgorithmException, UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static final String digestAlgorithm = "SHA-512";
    private static final String stringEncoding = "UTF-8";

    public static byte[] digest(String value, byte[] salt, int iterations)
            throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
        digest.reset();/*from   ww w .  j av  a 2 s  .c o m*/
        digest.update(salt);

        byte[] byteValue = digest.digest(value.getBytes(stringEncoding));
        for (int i = 0; i < iterations; ++i) {
            digest.reset();
            byteValue = digest.digest(byteValue);
        }

        return byteValue;
    }
}

Related

  1. digest(String text)
  2. digest(String text, String algorithm)
  3. digest(String token)
  4. digest(String type, byte[] bytes)
  5. digest(String uri)
  6. digest(String value, String algorithm)
  7. digestBased(String text)
  8. digestBySHA256(byte[] source)
  9. digestBytes(String type, byte[]... data)