代码如下:

  1. package com.lekou.utils;
  2.  
  3. public class MD5key {
  4.  
  5. ;
  6. ;
  7. ;
  8. ;
  9. ;
  10. ;
  11. ;
  12. ;
  13. ;
  14. ;
  15. ;
  16. ;
  17. ;
  18. ;
  19. ;
  20. ;
  21.  
  22. , , , , , , , , , , , , ,
  23. , , , , , , , , , , , , , , , , , , , , , ,
  24. , , , , , , , , , , , , , , , , , , , , , ,
  25. , , , , , , };
  26.  
  27. ]; // state (ABCD)
  28.  
  29. ]; // number of bits, modulo 2^64 (lsb
  30. // first)
  31. ]; // input buffer
  32.  
  33. public String digestHexStr;
  34.  
  35. ];
  36.  
  37. public String getkeyBeanofStr(String inbuf) {
  38. keyBeanInit();
  39. keyBeanUpdate(inbuf.getBytes(), inbuf.length());
  40. keyBeanFinal();
  41. digestHexStr = "";
  42. ; i < ; i++) {
  43. digestHexStr += byteHEX(digest[i]);
  44. }
  45. return digestHexStr;
  46. }
  47.  
  48. public MD5key() {
  49. keyBeanInit();
  50. return;
  51. }
  52.  
  53. private void keyBeanInit() {
  54. count[] = 0L;
  55. count[] = 0L;
  56. // /* Load magic initialization constants.
  57. state[] = 0x67452301L;
  58. state[] = 0xefcdab89L;
  59. state[] = 0x98badcfeL;
  60. state[] = 0x10325476L;
  61. return;
  62. }
  63.  
  64. private long F(long x, long y, long z) {
  65. return (x & y) | ((~x) & z);
  66. }
  67.  
  68. private long G(long x, long y, long z) {
  69. return (x & z) | (y & (~z));
  70. }
  71.  
  72. private long H(long x, long y, long z) {
  73. return x ^ y ^ z;
  74. }
  75.  
  76. private long I(long x, long y, long z) {
  77. return y ^ (x | (~z));
  78. }
  79.  
  80. private long FF(long a, long b, long c, long d, long x, long s, long ac) {
  81. a += F(b, c, d) + x + ac;
  82. a = (( - s));
  83. a += b;
  84. return a;
  85. }
  86.  
  87. private long GG(long a, long b, long c, long d, long x, long s, long ac) {
  88. a += G(b, c, d) + x + ac;
  89. a = (( - s));
  90. a += b;
  91. return a;
  92. }
  93.  
  94. private long HH(long a, long b, long c, long d, long x, long s, long ac) {
  95. a += H(b, c, d) + x + ac;
  96. a = (( - s));
  97. a += b;
  98. return a;
  99. }
  100.  
  101. private long II(long a, long b, long c, long d, long x, long s, long ac) {
  102. a += I(b, c, d) + x + ac;
  103. a = (( - s));
  104. a += b;
  105. return a;
  106. }
  107.  
  108. private void keyBeanUpdate(byte[] inbuf, int inputLen) {
  109. int i, index, partLen;
  110. ];
  111. index = (] >>> ) & 0x3F;
  112. // /* Update number of bits */
  113. ] += (inputLen << )) < (inputLen << ))
  114. count[]++;
  115. count[] += (inputLen >>> );
  116. partLen = - index;
  117. // Transform as many times as possible.
  118. if (inputLen >= partLen) {
  119. keyBeanMemcpy(buffer, inbuf, index, , partLen);
  120. keyBeanTransform(buffer);
  121. < inputLen; i += ) {
  122. keyBeanMemcpy(block, inbuf, , i, );
  123. keyBeanTransform(block);
  124. }
  125. index = ;
  126. } else
  127. i = ;
  128. // /* Buffer remaining input */
  129. keyBeanMemcpy(buffer, inbuf, index, i, inputLen - i);
  130. }
  131.  
  132. private void keyBeanFinal() {
  133. ];
  134. int index, padLen;
  135. // /* Save number of bits */
  136. Encode(bits, count, );
  137. // /* Pad out to 56 mod 64.
  138. index = (] >>> ) & 0x3f;
  139. padLen = (index < ) ? ( - index) : ( - index);
  140. keyBeanUpdate(PADDING, padLen);
  141. // /* Append length (before padding) */
  142. keyBeanUpdate(bits, );
  143. // /* Store state in digest */
  144. Encode(digest, state, );
  145. }
  146.  
  147. private void keyBeanMemcpy(byte[] output, byte[] input, int outpos,
  148. int inpos, int len) {
  149. int i;
  150. ; i < len; i++)
  151. output[outpos + i] = input[inpos + i];
  152. }
  153.  
  154. private void keyBeanTransform(byte block[]) {
  155. ], b = state[], c = state[], d = state[];
  156. ];
  157. Decode(x, block, );
  158. /* Round 1 */
  159. a = FF(a, b, c, d, x[], S11, 0xd76aa478L); /* 1 */
  160. d = FF(d, a, b, c, x[], S12, 0xe8c7b756L); /* 2 */
  161. c = FF(c, d, a, b, x[], S13, 0x242070dbL); /* 3 */
  162. b = FF(b, c, d, a, x[], S14, 0xc1bdceeeL); /* 4 */
  163. a = FF(a, b, c, d, x[], S11, 0xf57c0fafL); /* 5 */
  164. d = FF(d, a, b, c, x[], S12, 0x4787c62aL); /* 6 */
  165. c = FF(c, d, a, b, x[], S13, 0xa8304613L); /* 7 */
  166. b = FF(b, c, d, a, x[], S14, 0xfd469501L); /* 8 */
  167. a = FF(a, b, c, d, x[], S11, 0x698098d8L); /* 9 */
  168. d = FF(d, a, b, c, x[], S12, 0x8b44f7afL); /* 10 */
  169. c = FF(c, d, a, b, x[], S13, 0xffff5bb1L); /* 11 */
  170. b = FF(b, c, d, a, x[], S14, 0x895cd7beL); /* 12 */
  171. a = FF(a, b, c, d, x[], S11, 0x6b901122L); /* 13 */
  172. d = FF(d, a, b, c, x[], S12, 0xfd987193L); /* 14 */
  173. c = FF(c, d, a, b, x[], S13, 0xa679438eL); /* 15 */
  174. b = FF(b, c, d, a, x[], S14, 0x49b40821L); /* 16 */
  175. /* Round 2 */
  176. a = GG(a, b, c, d, x[], S21, 0xf61e2562L); /* 17 */
  177. d = GG(d, a, b, c, x[], S22, 0xc040b340L); /* 18 */
  178. c = GG(c, d, a, b, x[], S23, 0x265e5a51L); /* 19 */
  179. b = GG(b, c, d, a, x[], S24, 0xe9b6c7aaL); /* 20 */
  180. a = GG(a, b, c, d, x[], S21, 0xd62f105dL); /* 21 */
  181. d = GG(d, a, b, c, x[], S22, 0x2441453L); /* 22 */
  182. c = GG(c, d, a, b, x[], S23, 0xd8a1e681L); /* 23 */
  183. b = GG(b, c, d, a, x[], S24, 0xe7d3fbc8L); /* 24 */
  184. a = GG(a, b, c, d, x[], S21, 0x21e1cde6L); /* 25 */
  185. d = GG(d, a, b, c, x[], S22, 0xc33707d6L); /* 26 */
  186. c = GG(c, d, a, b, x[], S23, 0xf4d50d87L); /* 27 */
  187. b = GG(b, c, d, a, x[], S24, 0x455a14edL); /* 28 */
  188. a = GG(a, b, c, d, x[], S21, 0xa9e3e905L); /* 29 */
  189. d = GG(d, a, b, c, x[], S22, 0xfcefa3f8L); /* 30 */
  190. c = GG(c, d, a, b, x[], S23, 0x676f02d9L); /* 31 */
  191. b = GG(b, c, d, a, x[], S24, 0x8d2a4c8aL); /* 32 */
  192. /* Round 3 */
  193. a = HH(a, b, c, d, x[], S31, 0xfffa3942L); /* 33 */
  194. d = HH(d, a, b, c, x[], S32, 0x8771f681L); /* 34 */
  195. c = HH(c, d, a, b, x[], S33, 0x6d9d6122L); /* 35 */
  196. b = HH(b, c, d, a, x[], S34, 0xfde5380cL); /* 36 */
  197. a = HH(a, b, c, d, x[], S31, 0xa4beea44L); /* 37 */
  198. d = HH(d, a, b, c, x[], S32, 0x4bdecfa9L); /* 38 */
  199. c = HH(c, d, a, b, x[], S33, 0xf6bb4b60L); /* 39 */
  200. b = HH(b, c, d, a, x[], S34, 0xbebfbc70L); /* 40 */
  201. a = HH(a, b, c, d, x[], S31, 0x289b7ec6L); /* 41 */
  202. d = HH(d, a, b, c, x[], S32, 0xeaa127faL); /* 42 */
  203. c = HH(c, d, a, b, x[], S33, 0xd4ef3085L); /* 43 */
  204. b = HH(b, c, d, a, x[], S34, 0x4881d05L); /* 44 */
  205. a = HH(a, b, c, d, x[], S31, 0xd9d4d039L); /* 45 */
  206. d = HH(d, a, b, c, x[], S32, 0xe6db99e5L); /* 46 */
  207. c = HH(c, d, a, b, x[], S33, 0x1fa27cf8L); /* 47 */
  208. b = HH(b, c, d, a, x[], S34, 0xc4ac5665L); /* 48 */
  209. /* Round 4 */
  210. a = II(a, b, c, d, x[], S41, 0xf4292244L); /* 49 */
  211. d = II(d, a, b, c, x[], S42, 0x432aff97L); /* 50 */
  212. c = II(c, d, a, b, x[], S43, 0xab9423a7L); /* 51 */
  213. b = II(b, c, d, a, x[], S44, 0xfc93a039L); /* 52 */
  214. a = II(a, b, c, d, x[], S41, 0x655b59c3L); /* 53 */
  215. d = II(d, a, b, c, x[], S42, 0x8f0ccc92L); /* 54 */
  216. c = II(c, d, a, b, x[], S43, 0xffeff47dL); /* 55 */
  217. b = II(b, c, d, a, x[], S44, 0x85845dd1L); /* 56 */
  218. a = II(a, b, c, d, x[], S41, 0x6fa87e4fL); /* 57 */
  219. d = II(d, a, b, c, x[], S42, 0xfe2ce6e0L); /* 58 */
  220. c = II(c, d, a, b, x[], S43, 0xa3014314L); /* 59 */
  221. b = II(b, c, d, a, x[], S44, 0x4e0811a1L); /* 60 */
  222. a = II(a, b, c, d, x[], S41, 0xf7537e82L); /* 61 */
  223. d = II(d, a, b, c, x[], S42, 0xbd3af235L); /* 62 */
  224. c = II(c, d, a, b, x[], S43, 0x2ad7d2bbL); /* 63 */
  225. b = II(b, c, d, a, x[], S44, 0xeb86d391L); /* 64 */
  226. state[] += a;
  227. state[] += b;
  228. state[] += c;
  229. state[] += d;
  230. }
  231.  
  232. private void Encode(byte[] output, long[] input, int len) {
  233. int i, j;
  234. , j = ; j < len; i++, j += ) {
  235. output[j] = (byte) (input[i] & 0xffL);
  236. output[j + ] = () & 0xffL);
  237. output[j + ] = () & 0xffL);
  238. output[j + ] = () & 0xffL);
  239. }
  240. }
  241.  
  242. private void Decode(long[] output, byte[] input, int len) {
  243. int i, j;
  244.  
  245. , j = ; j < len; i++, j += )
  246. output[i] = b2iu(input[j]) | (b2iu(input[j + ]) << )
  247. | (b2iu(input[j + ]) << ) | (b2iu(input[j + ]) << );
  248. return;
  249. }
  250.  
  251. public static long b2iu(byte b) {
  252. ? b & : b;
  253. }
  254.  
  255. public static String byteHEX(byte ib) {
  256. ', 'A',
  257. 'B', 'C', 'D', 'E', 'F' };
  258. ];
  259. ob[] = Digit[(ib >>> ) & 0X0F];
  260. ob[] = Digit[ib & 0X0F];
  261. String s = new String(ob);
  262. return s;
  263. }
  264. }

controller层这样实现:

  1. //注册新用户
  2. @RequestMapping("doRegister")
  3. @ResponseBody
  4. public int doRegister(User user,String randomCode,HttpServletRequest request) {
  5. ;
  6. String code = (String) request.getSession().getAttribute("randomCode");
  7. //验证码一致就做添加
  8. if(code.equals(randomCode)) {
  9. try {
  10. MD5key md5key = new MD5key();
  11. String password = md5key.getkeyBeanofStr(user.getPassword());
  12. user.setPassword(password);
  13.  
  14. i=service.insertRegister(user);
  15. } catch (Exception e) {
  16. e.printStackTrace();
  17. ;
  18. }
  19.  
  20. ) {
  21. ;
  22. }else {
  23. ;
  24. }
  25. }else {
  26. ;//验证码不一致
  27. }
  28. }

MD5key.java的更多相关文章

  1. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. java代码实现python2中aes加密经历

    背景: 因项目需要,需要将一个python2编写的aes加密方式改为java实现. 1.源python2实现 from Crypto.Cipher import AES from binascii i ...

  3. Java使用阿里云OSS对象存储上传图片

    原 Java使用阿里云OSS对象存储上传图片 2017年03月27日 10:47:28 陌上桑花开花 阅读数 26804更多 分类专栏: 工作案例总结 版权声明:本文为博主原创文章,遵循CC 4.0 ...

  4. 如何对用户的绑定的身份证真实性进行实名认证(java)

    现在随着对用户实名制的要求,因此用户提交的身份证信息经查需要检查是否为真实信息,我们需要对用户提交的身份证信息进行核验,具体操作步骤如下: 第一步 到认证平台注册账号:云亿互通--实名认证服务 (yu ...

  5. 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题

    背景起因: 记起以前的另一次也是关于内存的调优分享下   有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...

  6. Elasticsearch之java的基本操作一

    摘要   接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...

  7. 论:开发者信仰之“天下IT是一家“(Java .NET篇)

    比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...

  8. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  9. 死磕内存篇 --- JAVA进程和linux内存间的大小关系

    运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...

随机推荐

  1. Javascript登录页面“记住密码”实现

    JS记住密码实现效果:  JavaScript Code  1234567891011121314151617181920212223242526272829303132   <!DOCTYPE ...

  2. python中WSGI是什么

    uswgi学习文档 http://uwsgi-docs-cn.readthedocs.io/zh_CN/latest/WSGIquickstart.html WSGI是什么? WSGI,全称 Web ...

  3. html5 canvas 详细使用教程 转

     分类: html5(9)  原文地址:http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html 原作很强悍 导航 前言 基本知识 绘 ...

  4. 【BZOJ3190】[JLOI2013]赛车 单调栈+几何

    [BZOJ3190][JLOI2013]赛车 Description 这里有一辆赛车比赛正在进行,赛场上一共有N辆车,分别称为个g1,g2……gn.赛道是一条无限长的直线.最初,gi位于距离起跑线前进 ...

  5. 《从零开始学Swift》学习笔记(Day 63)——Cocoa Touch设计模式及应用之单例模式

    原创文章,欢迎转载.转载请注明:关东升的博客 什么是设计模式.设计模式是在特定场景下对特定问题的解决方案,这些解决方案是经过反复论证和测试总结出来的.实际上,除了软件设计,设计模式也被广泛应用于其他领 ...

  6. phantomjs学习之截图

    1.创建pageload.js文件: pageload.js var page = require('webpage').create(); var address = 'https://www.ba ...

  7. 6.javaScript中的二维数组

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. tomcat8以上管理页面提示403问题

    修改conf/tomcat-users.xml <role rolename="manager"/> <role rolename="manager-g ...

  9. 使用jQuery重用form表单并异步提交到其它action

    在做页面开发的时候,有时候要重用表单的数据,并异步请求提交到其它的链接中,这个时候就能够使用jquery去改动表单的action值(记得使用后改动回来).并调用submit方法,当然后台的链接acti ...

  10. R语言操作mysql上亿数据量(ff包ffbase包和ETLUtils包)

    平时都是几百万的数据量,这段时间公司中了个大标,有上亿的数据量. 现在情况是数据已经在数据库里面了,需要用R分析,但是完全加载不进来内存. 面对现在这种情况,R提供了ff, ffbase , ETLU ...