[#1] Add additional security

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-07-24 14:41:42 +03:00
parent bf2f19f08d
commit 1be65c63ae
62 changed files with 670 additions and 281 deletions

View file

@ -8,9 +8,17 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.isNull;
public class Helper {
private Helper() {
}
public static byte[] getRIPEMD160(byte[] value) {
if (isNull(value)) {
throw new IllegalArgumentException("Input value is missing");
}
var hash = new byte[20];
var digest = new RIPEMD160Digest();
digest.update(value, 0, value.length);
@ -27,14 +35,26 @@ public class Helper {
}
public static byte[] getSha256(byte[] value) {
if (isNull(value)) {
throw new IllegalArgumentException("Input value is missing");
}
return getSha256Instance().digest(value);
}
public static ByteString getSha256(Message value) {
if (isNull(value)) {
throw new IllegalArgumentException("Input value is missing");
}
return ByteString.copyFrom(getSha256(value.toByteArray()));
}
public static String getHexString(byte[] array) {
return String.format("%0" + (array.length << 1) + "x", new BigInteger(1, array));
public static String getHexString(byte[] value) {
if (isNull(value)) {
throw new IllegalArgumentException("Input value is missing");
}
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));
}
}