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[] ...
随机推荐
- Javascript登录页面“记住密码”实现
JS记住密码实现效果: JavaScript Code 1234567891011121314151617181920212223242526272829303132 <!DOCTYPE ...
- python中WSGI是什么
uswgi学习文档 http://uwsgi-docs-cn.readthedocs.io/zh_CN/latest/WSGIquickstart.html WSGI是什么? WSGI,全称 Web ...
- html5 canvas 详细使用教程 转
分类: html5(9) 原文地址:http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html 原作很强悍 导航 前言 基本知识 绘 ...
- 【BZOJ3190】[JLOI2013]赛车 单调栈+几何
[BZOJ3190][JLOI2013]赛车 Description 这里有一辆赛车比赛正在进行,赛场上一共有N辆车,分别称为个g1,g2……gn.赛道是一条无限长的直线.最初,gi位于距离起跑线前进 ...
- 《从零开始学Swift》学习笔记(Day 63)——Cocoa Touch设计模式及应用之单例模式
原创文章,欢迎转载.转载请注明:关东升的博客 什么是设计模式.设计模式是在特定场景下对特定问题的解决方案,这些解决方案是经过反复论证和测试总结出来的.实际上,除了软件设计,设计模式也被广泛应用于其他领 ...
- phantomjs学习之截图
1.创建pageload.js文件: pageload.js var page = require('webpage').create(); var address = 'https://www.ba ...
- 6.javaScript中的二维数组
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- tomcat8以上管理页面提示403问题
修改conf/tomcat-users.xml <role rolename="manager"/> <role rolename="manager-g ...
- 使用jQuery重用form表单并异步提交到其它action
在做页面开发的时候,有时候要重用表单的数据,并异步请求提交到其它的链接中,这个时候就能够使用jquery去改动表单的action值(记得使用后改动回来).并调用submit方法,当然后台的链接acti ...
- R语言操作mysql上亿数据量(ff包ffbase包和ETLUtils包)
平时都是几百万的数据量,这段时间公司中了个大标,有上亿的数据量. 现在情况是数据已经在数据库里面了,需要用R分析,但是完全加载不进来内存. 面对现在这种情况,R提供了ff, ffbase , ETLU ...