Java Digest digestBySHA256(byte[] source)

Here you can find the source of digestBySHA256(byte[] source)

Description

digest

License

Open Source License

Parameter

Parameter Description
source a parameter

Declaration

public static byte[] digestBySHA256(byte[] source) 

Method Source Code


//package com.java2s;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static final String DIGEST_SHA_256 = "SHA-256";

    /**//  ww  w  .  ja v  a  2 s  .c om
     * digest
     * 
     * @param source
     * @return
     */
    public static byte[] digestBySHA256(byte[] source) {
        MessageDigest md5Digest = getDigest(DIGEST_SHA_256);
        return md5Digest.digest(source);
    }

    private static MessageDigest getDigest(String algorithm) {
        try {
            return MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("Could not find MessageDigest with algorithm \"" + algorithm + "\"", e);
        }
    }

    private static byte[] digest(String algorithm, byte[] bytes) {
        return getDigest(algorithm).digest(bytes);
    }
}

Related

  1. digest(String type, byte[] bytes)
  2. digest(String uri)
  3. digest(String value, byte[] salt, int iterations)
  4. digest(String value, String algorithm)
  5. digestBased(String text)
  6. digestBytes(String type, byte[]... data)
  7. digestEncrypte(byte[] plainText, String algorithm)
  8. digestHex(String txt)
  9. digestHmacToBase64(String algorithm, String msg, byte[] privateKey)