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[]SHA256(byte[] src)
SHA
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(src);
    return md.digest();
} catch (Exception e) {
return null;
byte[]SHA256(ByteBuffer buf, int off, int length)
SHA
int limit = buf.limit();
int position = buf.position();
if (off + length > limit) {
    return null;
buf.position(off);
buf.limit(off + length);
try {
...
byte[]sha256(final InputStream inputStream)
Calculate the SHA-256 hash over the bytes read from the given input stream
Objects.requireNonNull(inputStream);
try {
    final byte[] buffer = new byte[BUFFER_SIZE];
    final MessageDigest digest = MessageDigest.getInstance("SHA-256");
    int bytesRead;
    while ((bytesRead = inputStream.read(buffer)) != -1) {
        digest.update(buffer, 0, bytesRead);
    return digest.digest();
} catch (NoSuchAlgorithmException e) {
    throw new IllegalStateException("SHA-256 hashing algorithm unknown in this VM.", e);
Stringsha256(final String string)
sha
if (string == null) {
    throw new IllegalArgumentException("Argument cannot be null");
try {
    final MessageDigest digest = MessageDigest.getInstance("SHA-256");
    final byte[] hash = digest.digest(string.getBytes("UTF-8"));
    final StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < hash.length; i++) {
...
Stringsha256(InputStream data)
sha
MessageDigest digest = getDigest("SHA-256");
byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
int read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
while (read > -1) {
    digest.update(buffer, 0, read);
    read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
return asHex(digest.digest());
...
Stringsha256(String base)
Calcola l'hash crittografico di una stringa di input tramite SHA-256.
try {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    byte[] hash = digest.digest(base.getBytes("UTF-8"));
    StringBuilder hexString = new StringBuilder();
    for (byte b : hash) {
        String hex = Integer.toHexString(0xff & b);
        if (hex.length() == 1)
            hexString.append('0');
...
Stringsha256(String base)
sha
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(base.getBytes());
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
    String hex = Integer.toHexString(0xff & hash[i]);
    if (hex.length() == 1) {
        hexString.append('0');
    hexString.append(hex);
return hexString.toString();
Stringsha256(String data)
sha
return byte2hex(MessageDigest.getInstance("SHA-256").digest(data.getBytes()));
Stringsha256(String Input)
sha
String Return = Input;
MessageDigest MessageD = MessageDigest.getInstance("SHA-256");
MessageD.update(Return.getBytes(), 0, Return.length());
return new BigInteger(1, MessageD.digest()).toString(16);
StringSHA256(String input)
SHA
return toHexString(SHA256byte(input));