use of java.security.MessageDigest in project j2objc by google.
the class MessageDigest2Test method test_getAlgorithm.
/**
* java.security.MessageDigest#getAlgorithm()
*/
public void test_getAlgorithm() throws Exception {
for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
for (String algorithm : e.getValue()) {
MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
assertEquals(algorithm, md.getAlgorithm());
}
}
}
use of java.security.MessageDigest in project j2objc by google.
the class MessageDigest2Test method test_getDigestLength.
/**
* java.security.MessageDigest#getDigestLength()
*/
public void test_getDigestLength() throws Exception {
for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
for (String algorithm : e.getValue()) {
MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
assertTrue("length not ok", md.getDigestLength() > 0);
}
}
}
use of java.security.MessageDigest in project liquibase by liquibase.
the class MD5Util method computeMD5.
public static String computeMD5(String input) {
if (input == null) {
return null;
}
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
digest.update(input.getBytes(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
} catch (Exception e) {
throw new UnexpectedLiquibaseException(e);
}
byte[] digestBytes = digest.digest();
String returnString = new String(encodeHex(digestBytes));
String inputToLog = input;
if (inputToLog.length() > 500) {
inputToLog = inputToLog.substring(0, 500) + "... [truncated in log]";
}
LogFactory.getLogger().debug("Computed checksum for " + inputToLog + " as " + returnString);
return returnString;
}
use of java.security.MessageDigest in project liquibase by liquibase.
the class MD5Util method computeMD5.
public static String computeMD5(InputStream stream) {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
DigestInputStream digestStream = new DigestInputStream(stream, digest);
byte[] buf = new byte[20480];
while (digestStream.read(buf) != -1) {
//digest is updating
;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
byte[] digestBytes = digest.digest();
String returnString = new String(encodeHex(digestBytes));
LogFactory.getLogger().debug("Computed checksum for inputStream as " + returnString);
return returnString;
}
use of java.security.MessageDigest in project android-common by litesuits.
the class MD5Util method md5.
public static byte[] md5(byte[] bytes) {
try {
MessageDigest digest = getDigest("MD5");
digest.update(bytes);
return digest.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
Aggregations