Here you can find the source of digestBySHA256(byte[] source)
Parameter | Description |
---|---|
source | a parameter |
public static byte[] digestBySHA256(byte[] source)
//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); } }