package info.FrostFS.sdk; import com.google.protobuf.AbstractMessage; import com.google.protobuf.ByteString; import org.bouncycastle.crypto.digests.RIPEMD160Digest; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Helper { public static byte[] getRIPEMD160(byte[] value) { var hash = new byte[20]; var digest = new RIPEMD160Digest(); digest.update(value, 0, value.length); digest.doFinal(hash, 0); return hash; } public static MessageDigest getSha256Instance() { try { return MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } public static byte[] getSha256(byte[] value) { return getSha256Instance().digest(value); } public static ByteString getSha256(AbstractMessage value) { return ByteString.copyFrom(getSha256(value.toByteArray())); } public static String getHexString(byte[] array) { return String.format("%0" + (array.length << 1) + "x", new BigInteger(1, array)); } }