frostfs-sdk-java/cryptography/src/main/java/info/FrostFS/sdk/Helper.java
Bruk Ori b0db7df192 [#1] add client environment
add client cut
code cleanup
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
2024-07-24 15:49:12 +03:00

40 lines
1.1 KiB
Java

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));
}
}