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[] ...
随机推荐
- ChemDraw的“键”工具的作用是什么
ChemDraw的“键”工具在化学研究中能够发挥重大作用,如果你也是一名化学相关工作者就千万不要错过这篇教程,下文详细盘点“键”工具究竟能干些什么. ChemDraw化学软件免费获取地址:http:/ ...
- JavaScript------日期和时间戳的相互转换
var date = new Date(); 日期转时间戳 Number(date)或者date.getTime(); //只是转换成了纯数字的时间戳,例如:1498144203861需要转换才能使用 ...
- UIWebview打开.txt文件中文乱码解决
用UIWebview打开txt文件有时候会出现乱码的情况,这种情况应该是txt的编码问题,解决方案如下: txt分带编码和不带编码两种,带编码的如UTF-8格式txt,不带编码的如ANSI格式txt. ...
- jeesite学习笔记(一) 项目框架
JeeSite是基于多个优秀的开源项目,高度整合封装而成的高效,高性能,强安全性的开源Java EE快速开发平台. 在github上,对jeesite平台有详细的介绍,这里稍作整理,给出项目的内置功能 ...
- 大数据技术大合集:Hadoop家族、Cloudera系列、spark、storm【转】
大数据我们都知道hadoop,可是还会各种各样的技术进入我们的视野:Spark,Storm,impala,让我们都反映不过来.为了能够更好 的架构大数据项目,这里整理一下,供技术人员,项目经理,架构师 ...
- 用 Stellar.js 制作视差滚动效果
参考 http://doc.bropaul.com/Stellar.js/docs/ https://github.com/markdalgleish/stellar.js#download http ...
- mysql数据库表卡死怎么办
- 解决思路就是找到等待的线程并kill -- 查看所有进程 1.SHOW PROCESSLIST; 2.找到卡死或在等待的线程,kill,假设这里是49496卡死了 KILL 49496;
- bootstrap-table固定表头固定列
1.引入 bootstrap依赖于jquery bootstrap-table依赖于bootstrap,所以都需要引入 2. bootstrap-table有两种方式,html.js <tabl ...
- 理解Python的双下划线命名
引子 我热情地邀请大家猜测下面这段程序的输出: class A(object): def __init__(self): self.__private() ...
- 修改hosts文件不起作用
今天遇到个很奇怪的问题,在hosts文件里添加了一些域名指向后,发现根本没起作用,后来还发现个细节,就是hosts文件左下角有个小锁的标志,开始以为是杀毒软件之类的把他锁了.可是没找到在哪里有相关操作 ...