use of java.security.MessageDigest in project gitblit by gitblit.
the class StringUtils method getSHA1.
/**
* Calculates the SHA1 of the byte array.
*
* @param bytes
* @return sha1 of the byte array
*/
public static String getSHA1(byte[] bytes) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(bytes, 0, bytes.length);
byte[] digest = md.digest();
return toHex(digest);
} catch (NoSuchAlgorithmException t) {
throw new RuntimeException(t);
}
}
use of java.security.MessageDigest in project gitblit by gitblit.
the class DeepCopier method checksum.
/**
* Utility method to calculate the checksum of an object.
* @param sourceObject The object from which to establish the checksum.
* @return The checksum
* @throws IOException
*/
public static BigInteger checksum(Object sourceObject) {
if (sourceObject == null) {
return BigInteger.ZERO;
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(sourceObject);
oos.close();
MessageDigest m = MessageDigest.getInstance("SHA-1");
m.update(baos.toByteArray());
return new BigInteger(1, m.digest());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
// impossible
}
return BigInteger.ZERO;
}
use of java.security.MessageDigest in project buck by facebook.
the class DexFile method calcSignature.
/**
* Calculates the signature for the {@code .dex} file in the
* given array, and modify the array to contain it.
*
* @param bytes {@code non-null;} the bytes of the file
*/
private static void calcSignature(byte[] bytes) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
md.update(bytes, 32, bytes.length - 32);
try {
int amt = md.digest(bytes, 12, 20);
if (amt != 20) {
throw new RuntimeException("unexpected digest write: " + amt + " bytes");
}
} catch (DigestException ex) {
throw new RuntimeException(ex);
}
}
use of java.security.MessageDigest in project fresco by facebook.
the class SecureHashUtil method makeHash.
private static String makeHash(byte[] bytes, String algorithm) {
try {
MessageDigest md = MessageDigest.getInstance(algorithm);
md.update(bytes, 0, bytes.length);
byte[] hash = md.digest();
return convertToHex(hash);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
use of java.security.MessageDigest in project XobotOS by xamarin.
the class HttpResponseCache method uriToKey.
private String uriToKey(URI uri) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] md5bytes = messageDigest.digest(uri.toString().getBytes(Charsets.UTF_8));
return IntegralToString.bytesToHexString(md5bytes, false);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
Aggregations