Java实现MD5
2016-12-20 21:59
190 查看
本文摘自:http://www.cnblogs.com/yanghuahui/archive/2013/06/16/3139411.html
经实践检测可行,以备以后使用。
import java.security.MessageDigest;
/**
* Created by Administrator on 2016/11/26.
*/
public class test {
public static void main(String[] args) {
MD5("test");
}
public static String MD5(String basicInfo){
char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
try {
byte[] strTemp = basicInfo.getBytes();
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(strTemp);
byte[] md = md5.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) {
e.printStackTrace();
return null;
}
}
}
经实践检测可行,以备以后使用。
import java.security.MessageDigest;
/**
* Created by Administrator on 2016/11/26.
*/
public class test {
public static void main(String[] args) {
MD5("test");
}
public static String MD5(String basicInfo){
char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
try {
byte[] strTemp = basicInfo.getBytes();
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(strTemp);
byte[] md = md5.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) {
e.printStackTrace();
return null;
}
}
}
相关文章推荐
- MD5 算法的java实现
- 一个实现MD5的简洁的java类
- 在Java中使用MessageDigest实现MD5,SHA-1等加密
- java md5 的实现
- MD5 的 Java 实现
- 一个实现MD5的简洁的java类
- Java实现的Base64、MD5、3DES工具
- JAVA中实现MD5的算法
- java md5 的实现
- Java实现的Base64、MD5、3DES工具
- Java的MD5实现
- 在Java中使用MessageDigest实现MD5,sha1等加密
- 用Java实现MD5,SHA-1等加密
- 实现MD5序列的生成[Java]
- JAVA MD5 算法实现
- 一个实现MD5的简洁的java类
- 一个实现MD5的java类
- 一个实现MD5的简洁的java类
- MD5 JAVA 加密 实现
- Java实现的Base64、MD5、3DES工具