Java Utililty Methods SHA256

List of utility methods to do SHA256

Description

The list of methods to do SHA256 are organized into topic(s).

Method

byte[]digestSHA256(byte[] input)
Performs a final update on the digest using the specified array of bytes, then completes the digest computation.
MessageDigest digestEngine = MessageDigest.getInstance("SHA-256");
return digestEngine.digest(input);
StringdigestSha256(String plain)
digest Sha
try {
    return digest(plain, "SHA-256");
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
byte[]digestSha256(String value)
Parses a string and returns a SHA-256 checksum of it.
final MessageDigest algorithm;
try {
    algorithm = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
return algorithm.digest(value.getBytes());
StringgetSHA256(String input)
get SHA
try {
    return DatatypeConverter.printHexBinary(md.digest(input.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
    System.err.println("[CRITICAL] UTF-8 ENCODING NOT SUPPORTED. EXITING.");
    System.exit(-1);
    return "ERROR"; 
MessageDigestsha256()
sha
try {
    return MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
    throw new IllegalStateException(e);
byte[]sha256(byte[] bytes)
sha
return MessageDigest.getInstance("SHA-256").digest(bytes);
byte[]sha256(byte[] data)
sha
return sha256(data, 0, data.length);
Stringsha256(byte[] data)
Compute a SHA-256 hash using Java built-in MessageDigest, and format the result in hex.
try {
    MessageDigest md = MessageDigest.getInstance("sha-256", "SUN");
    byte[] sign = md.digest(data);
    return arraytohexstring(sign);
} catch (NoSuchAlgorithmException | NoSuchProviderException imp) {
    throw new RuntimeException(imp);
byte[]SHA256(byte[] input)
SHA
return sha256.digest(input);
StringSHA256(byte[] P)
SHA
try {
    MessageDigest SIG = MessageDigest.getInstance("SHA-256");
    SIG.update(P, 0, P.length);
    byte D[] = SIG.digest();
    return getHexString(D);
} catch (java.security.NoSuchAlgorithmException e) {
    throw new RuntimeException(e);