use of java.security.MessageDigest in project jdbc-shards by wplatform.
the class KetamaHash method computeMd5.
private static byte[] computeMd5(String k) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(k.getBytes("UTF-8"));
return md5.digest();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5 not supported", e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unknown string :" + k, e);
}
}
use of java.security.MessageDigest in project XobotOS by xamarin.
the class SslCertificate method getDigest.
/**
* Convenience for UI presentation, not intended as public API.
*/
private static String getDigest(X509Certificate x509Certificate, String algorithm) {
if (x509Certificate == null) {
return "";
}
try {
byte[] bytes = x509Certificate.getEncoded();
MessageDigest md = MessageDigest.getInstance(algorithm);
byte[] digest = md.digest(bytes);
return fingerprint(digest);
} catch (CertificateEncodingException ignored) {
return "";
} catch (NoSuchAlgorithmException ignored) {
return "";
}
}
use of java.security.MessageDigest in project VitamioBundle by yixia.
the class Crypto method md5.
public static String md5(String plain) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(plain.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1, digest);
String hashtext = bigInt.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
} catch (Exception e) {
return "";
}
}
use of java.security.MessageDigest in project mysql_perf_analyzer by yahoo.
the class MD5Util method MD5.
public static String MD5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte[] md5hash = null;
md.update(text.getBytes("iso-8859-1"), 0, text.length());
md5hash = md.digest();
return convertToHex(md5hash);
}
use of java.security.MessageDigest in project translationstudio8 by heartsome.
the class Md5Encode method encode.
/**
* 加密.
* @param s
* 要加密的字符串
* @return String
* 加密后的字符串
*/
public static final String encode(String s) {
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char[] str = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}
Aggregations