forked from TrueCloudLab/frostfs-sdk-java
[#1] provide naming conventions
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
a7fab6f314
commit
bf2f19f08d
103 changed files with 416 additions and 417 deletions
40
cryptography/src/main/java/info/frostfs/sdk/Helper.java
Normal file
40
cryptography/src/main/java/info/frostfs/sdk/Helper.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package info.frostfs.sdk;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
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(Message 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));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue