下载此文档

MD5加解密及测试方法.doc


文档分类:IT计算机 | 页数:约24页 举报非法文档有奖
1/24
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/24 下载此文档
文档列表 文档介绍
Java实现MD5加密解密类收藏
转载请注明:来自http://blog./M_ChangGong/ 作者:张燕广
Java实现MD5加密以及解密类,附带测试类,具体见代码。
MD5加密解密类——MyMD5Util,代码如下:
view plaincopy to clipboardprint?
01..;
02.
;
;
;
;
;
08.
class MyMD5Util {
10.
11. private static final String HEX_NUMS_STR="0123456789ABCDEF";
12. private static final Integer SALT_LENGTH = 12;
13.
14. /**
15. * 将16进制字符串转换成字节数组
16. * ***@param hex
17. * ***@return
18. */
19. public static byte[] hexStringToByte(String hex) {
20. int len = (() / 2);
21. byte[] result = new byte[len];
22. char[] hexChars = ();
23. for (int i = 0; i < len; i++) {
24. int pos = i * 2;
25. result[i] = (byte) ((hexChars[pos]) << 4
26. | (hexChars[pos + 1]));
27. }
28. return result;
29. }
30.
31.
32. /**
33. * 将指定byte数组转换成16进制字符串
34. * ***@param b
35. * ***@return
36. */
37. public static String byteToHexString(byte[] b) {
38. StringBuffer hexString = new StringBuffer();
39. for (int i = 0; i < ; i++) {
40. String hex = (b[i] & 0xFF);
41. if (() == 1) {
42. hex = '0' + hex;
43. }
44. (());
45. }
46. return ();
47. }
48.
49. /**
50. * 验证口令是否合法
51. * ***@param password
52. * ***@param passwordInDb
53. * ***@return
54. * ***@throws NoSuchAlgorithmException
55. * ***@throws UnsupportedEncodingException
56. */
57. public static boolean validPassword(String password, String passwordInDb)
58. throws NoSuchAlgorithmException, UnsupportedEncodingException {
59. //将16进制字符串格式口令转换成字节数组
60. byte[] pwdInDb = hexStringToByte(passwordInDb);
61. //声明盐变量
62. byte[] salt = new byte[SALT_LENGTH];
63. //将盐从数据库中保存的口令字节数组中提取出来
64. System.

MD5加解密及测试方法 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数24
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xgs758698
  • 文件大小0 KB
  • 时间2015-05-23