「Java」文字列をMD5で暗号化するコード

Javaコード
public class DataMd5Deal {
public final static String MD5(String s){
char hs[] = {
'0’, '1’, '2’, '3’, '4’, '5’, '6’, '7’, '8’, '9’, 'a’, 'b’, 'c’, 'd’,
'e’, 'f’};
try {
byte[] strp = s.getBytes();
MessageDigest mdt = MessageDigest.getInstance(“MD5");
mdt.update(strp);
byte[] md = mdt.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++] = hs[byte0 >>> 4 & 0xf];
str[k++] = hs[byte0 & 0xf];
}
return new String(str);
}
catch (Exception e)
{
return null;
}
}
}

Java

Posted by arkgame