MD5key.java
代码如下:
package com.lekou.utils; public class MD5key { ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , }; ]; // state (ABCD) ]; // number of bits, modulo 2^64 (lsb // first) ]; // input buffer public String digestHexStr; ]; public String getkeyBeanofStr(String inbuf) { keyBeanInit(); keyBeanUpdate(inbuf.getBytes(), inbuf.length()); keyBeanFinal(); digestHexStr = ""; ; i < ; i++) { digestHexStr += byteHEX(digest[i]); } return digestHexStr; } public MD5key() { keyBeanInit(); return; } private void keyBeanInit() { count[] = 0L; count[] = 0L; // /* Load magic initialization constants. state[] = 0x67452301L; state[] = 0xefcdab89L; state[] = 0x98badcfeL; state[] = 0x10325476L; return; } private long F(long x, long y, long z) { return (x & y) | ((~x) & z); } private long G(long x, long y, long z) { return (x & z) | (y & (~z)); } private long H(long x, long y, long z) { return x ^ y ^ z; } private long I(long x, long y, long z) { return y ^ (x | (~z)); } private long FF(long a, long b, long c, long d, long x, long s, long ac) { a += F(b, c, d) + x + ac; a = (( - s)); a += b; return a; } private long GG(long a, long b, long c, long d, long x, long s, long ac) { a += G(b, c, d) + x + ac; a = (( - s)); a += b; return a; } private long HH(long a, long b, long c, long d, long x, long s, long ac) { a += H(b, c, d) + x + ac; a = (( - s)); a += b; return a; } private long II(long a, long b, long c, long d, long x, long s, long ac) { a += I(b, c, d) + x + ac; a = (( - s)); a += b; return a; } private void keyBeanUpdate(byte[] inbuf, int inputLen) { int i, index, partLen; ]; index = (] >>> ) & 0x3F; // /* Update number of bits */ ] += (inputLen << )) < (inputLen << )) count[]++; count[] += (inputLen >>> ); partLen = - index; // Transform as many times as possible. if (inputLen >= partLen) { keyBeanMemcpy(buffer, inbuf, index, , partLen); keyBeanTransform(buffer); < inputLen; i += ) { keyBeanMemcpy(block, inbuf, , i, ); keyBeanTransform(block); } index = ; } else i = ; // /* Buffer remaining input */ keyBeanMemcpy(buffer, inbuf, index, i, inputLen - i); } private void keyBeanFinal() { ]; int index, padLen; // /* Save number of bits */ Encode(bits, count, ); // /* Pad out to 56 mod 64. index = (] >>> ) & 0x3f; padLen = (index < ) ? ( - index) : ( - index); keyBeanUpdate(PADDING, padLen); // /* Append length (before padding) */ keyBeanUpdate(bits, ); // /* Store state in digest */ Encode(digest, state, ); } private void keyBeanMemcpy(byte[] output, byte[] input, int outpos, int inpos, int len) { int i; ; i < len; i++) output[outpos + i] = input[inpos + i]; } private void keyBeanTransform(byte block[]) { ], b = state[], c = state[], d = state[]; ]; Decode(x, block, ); /* Round 1 */ a = FF(a, b, c, d, x[], S11, 0xd76aa478L); /* 1 */ d = FF(d, a, b, c, x[], S12, 0xe8c7b756L); /* 2 */ c = FF(c, d, a, b, x[], S13, 0x242070dbL); /* 3 */ b = FF(b, c, d, a, x[], S14, 0xc1bdceeeL); /* 4 */ a = FF(a, b, c, d, x[], S11, 0xf57c0fafL); /* 5 */ d = FF(d, a, b, c, x[], S12, 0x4787c62aL); /* 6 */ c = FF(c, d, a, b, x[], S13, 0xa8304613L); /* 7 */ b = FF(b, c, d, a, x[], S14, 0xfd469501L); /* 8 */ a = FF(a, b, c, d, x[], S11, 0x698098d8L); /* 9 */ d = FF(d, a, b, c, x[], S12, 0x8b44f7afL); /* 10 */ c = FF(c, d, a, b, x[], S13, 0xffff5bb1L); /* 11 */ b = FF(b, c, d, a, x[], S14, 0x895cd7beL); /* 12 */ a = FF(a, b, c, d, x[], S11, 0x6b901122L); /* 13 */ d = FF(d, a, b, c, x[], S12, 0xfd987193L); /* 14 */ c = FF(c, d, a, b, x[], S13, 0xa679438eL); /* 15 */ b = FF(b, c, d, a, x[], S14, 0x49b40821L); /* 16 */ /* Round 2 */ a = GG(a, b, c, d, x[], S21, 0xf61e2562L); /* 17 */ d = GG(d, a, b, c, x[], S22, 0xc040b340L); /* 18 */ c = GG(c, d, a, b, x[], S23, 0x265e5a51L); /* 19 */ b = GG(b, c, d, a, x[], S24, 0xe9b6c7aaL); /* 20 */ a = GG(a, b, c, d, x[], S21, 0xd62f105dL); /* 21 */ d = GG(d, a, b, c, x[], S22, 0x2441453L); /* 22 */ c = GG(c, d, a, b, x[], S23, 0xd8a1e681L); /* 23 */ b = GG(b, c, d, a, x[], S24, 0xe7d3fbc8L); /* 24 */ a = GG(a, b, c, d, x[], S21, 0x21e1cde6L); /* 25 */ d = GG(d, a, b, c, x[], S22, 0xc33707d6L); /* 26 */ c = GG(c, d, a, b, x[], S23, 0xf4d50d87L); /* 27 */ b = GG(b, c, d, a, x[], S24, 0x455a14edL); /* 28 */ a = GG(a, b, c, d, x[], S21, 0xa9e3e905L); /* 29 */ d = GG(d, a, b, c, x[], S22, 0xfcefa3f8L); /* 30 */ c = GG(c, d, a, b, x[], S23, 0x676f02d9L); /* 31 */ b = GG(b, c, d, a, x[], S24, 0x8d2a4c8aL); /* 32 */ /* Round 3 */ a = HH(a, b, c, d, x[], S31, 0xfffa3942L); /* 33 */ d = HH(d, a, b, c, x[], S32, 0x8771f681L); /* 34 */ c = HH(c, d, a, b, x[], S33, 0x6d9d6122L); /* 35 */ b = HH(b, c, d, a, x[], S34, 0xfde5380cL); /* 36 */ a = HH(a, b, c, d, x[], S31, 0xa4beea44L); /* 37 */ d = HH(d, a, b, c, x[], S32, 0x4bdecfa9L); /* 38 */ c = HH(c, d, a, b, x[], S33, 0xf6bb4b60L); /* 39 */ b = HH(b, c, d, a, x[], S34, 0xbebfbc70L); /* 40 */ a = HH(a, b, c, d, x[], S31, 0x289b7ec6L); /* 41 */ d = HH(d, a, b, c, x[], S32, 0xeaa127faL); /* 42 */ c = HH(c, d, a, b, x[], S33, 0xd4ef3085L); /* 43 */ b = HH(b, c, d, a, x[], S34, 0x4881d05L); /* 44 */ a = HH(a, b, c, d, x[], S31, 0xd9d4d039L); /* 45 */ d = HH(d, a, b, c, x[], S32, 0xe6db99e5L); /* 46 */ c = HH(c, d, a, b, x[], S33, 0x1fa27cf8L); /* 47 */ b = HH(b, c, d, a, x[], S34, 0xc4ac5665L); /* 48 */ /* Round 4 */ a = II(a, b, c, d, x[], S41, 0xf4292244L); /* 49 */ d = II(d, a, b, c, x[], S42, 0x432aff97L); /* 50 */ c = II(c, d, a, b, x[], S43, 0xab9423a7L); /* 51 */ b = II(b, c, d, a, x[], S44, 0xfc93a039L); /* 52 */ a = II(a, b, c, d, x[], S41, 0x655b59c3L); /* 53 */ d = II(d, a, b, c, x[], S42, 0x8f0ccc92L); /* 54 */ c = II(c, d, a, b, x[], S43, 0xffeff47dL); /* 55 */ b = II(b, c, d, a, x[], S44, 0x85845dd1L); /* 56 */ a = II(a, b, c, d, x[], S41, 0x6fa87e4fL); /* 57 */ d = II(d, a, b, c, x[], S42, 0xfe2ce6e0L); /* 58 */ c = II(c, d, a, b, x[], S43, 0xa3014314L); /* 59 */ b = II(b, c, d, a, x[], S44, 0x4e0811a1L); /* 60 */ a = II(a, b, c, d, x[], S41, 0xf7537e82L); /* 61 */ d = II(d, a, b, c, x[], S42, 0xbd3af235L); /* 62 */ c = II(c, d, a, b, x[], S43, 0x2ad7d2bbL); /* 63 */ b = II(b, c, d, a, x[], S44, 0xeb86d391L); /* 64 */ state[] += a; state[] += b; state[] += c; state[] += d; } private void Encode(byte[] output, long[] input, int len) { int i, j; , j = ; j < len; i++, j += ) { output[j] = (byte) (input[i] & 0xffL); output[j + ] = () & 0xffL); output[j + ] = () & 0xffL); output[j + ] = () & 0xffL); } } private void Decode(long[] output, byte[] input, int len) { int i, j; , j = ; j < len; i++, j += ) output[i] = b2iu(input[j]) | (b2iu(input[j + ]) << ) | (b2iu(input[j + ]) << ) | (b2iu(input[j + ]) << ); return; } public static long b2iu(byte b) { ? b & : b; } public static String byteHEX(byte ib) { ', 'A', 'B', 'C', 'D', 'E', 'F' }; ]; ob[] = Digit[(ib >>> ) & 0X0F]; ob[] = Digit[ib & 0X0F]; String s = new String(ob); return s; } }
controller层这样实现:
//注册新用户 @RequestMapping("doRegister") @ResponseBody public int doRegister(User user,String randomCode,HttpServletRequest request) { ; String code = (String) request.getSession().getAttribute("randomCode"); //验证码一致就做添加 if(code.equals(randomCode)) { try { MD5key md5key = new MD5key(); String password = md5key.getkeyBeanofStr(user.getPassword()); user.setPassword(password); i=service.insertRegister(user); } catch (Exception e) { e.printStackTrace(); ; } ) { ; }else { ; } }else { ;//验证码不一致 } }
MD5key.java的更多相关文章
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- java代码实现python2中aes加密经历
背景: 因项目需要,需要将一个python2编写的aes加密方式改为java实现. 1.源python2实现 from Crypto.Cipher import AES from binascii i ...
- Java使用阿里云OSS对象存储上传图片
原 Java使用阿里云OSS对象存储上传图片 2017年03月27日 10:47:28 陌上桑花开花 阅读数 26804更多 分类专栏: 工作案例总结 版权声明:本文为博主原创文章,遵循CC 4.0 ...
- 如何对用户的绑定的身份证真实性进行实名认证(java)
现在随着对用户实名制的要求,因此用户提交的身份证信息经查需要检查是否为真实信息,我们需要对用户提交的身份证信息进行核验,具体操作步骤如下: 第一步 到认证平台注册账号:云亿互通--实名认证服务 (yu ...
- 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题
背景起因: 记起以前的另一次也是关于内存的调优分享下 有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...
- Elasticsearch之java的基本操作一
摘要 接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...
- 论:开发者信仰之“天下IT是一家“(Java .NET篇)
比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- 死磕内存篇 --- JAVA进程和linux内存间的大小关系
运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...
随机推荐
- node.js中的事件循环机制
http://www.cnblogs.com/dolphinX/p/3475090.html
- <转>RestKit在iOS项目中的使用,包含xcode配置说明
本文转载至 http://www.cnblogs.com/visen-0/archive/2012/05/03/2480693.html 最近在iPhone工程中添加RestKit并编译,但是由于之前 ...
- HDU 1875 畅通工程再续(kruskal)
畅通工程再续 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- android问题总结
1.当打开eclipse时出现如下窗口(内容如下) Error when loading the SDK: Error: Error parsing \Android\adt-bundle-windo ...
- 综合: Java 对象初始化过程
class Fu { Fu() { show(); } void show() { System.out.println("xixi"); } } class Zi extends ...
- Visualizing wave interference using FireMonkey(很美)
Visualizing wave interference using FireMonkey By: Anders Ohlsson Abstract: This article discusses ...
- 《深入理解Linux网络技术内幕》阅读笔记 --- 路由表
路由表基本概念 1.路由是由多个不同的数据结构的组合来描述的,每个数据结构代表路由信息的不同部分.例如,一个fib_node对应一个单独的子网,一个fib_alias对应一条路由.这样做的原因是只需通 ...
- CNI flannel插件
// plugins/meta/flannel/flannel.go func cmdAdd(args *skel.CmdArgs) error 调用n, err := loadFlannelNetC ...
- kubestack 源码分析
简介:KubeStack is an OpenStack network provider for kubernetes.KubeStack is devided into two functions ...
- tensorflow 的rnn的示例 ptb_word_lm.py 的完整代码
其训练数据源在我的空间里,名字为:tensorflow的ptb-word-lm示例的训练数据源.tgz 讲解参见另一篇文章: http://www.cnblogs.com/welhzh/p/6739 ...