All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.auties.whatsapp.crypto.Sha256 Maven / Gradle / Ivy

package it.auties.whatsapp.crypto;


import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class Sha256 {
    private static final String SHA_256 = "SHA-256";

    public static byte[] calculate(String data) {
        return calculate(data.getBytes(StandardCharsets.UTF_8));
    }

    public static byte[] calculate(byte[] data) {
        return calculate(data, 0, data.length);
    }

    public static byte[] calculate(byte[] data, int offset, int length) {
        try {
            var digest = MessageDigest.getInstance(SHA_256);
            digest.update(data, offset, length);
            return digest.digest();
        } catch (NoSuchAlgorithmException exception) {
            throw new UnsupportedOperationException("Missing sha256 implementation");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy