package Bean;
/************************************************
MD5 算法之Java Bean
@author:Topcat Tuppin
Last Modified:10,Mar,2001
*************************************************/
import java.lang.reflect.*;
/*************************************************
md5 类实现了RSA Data Security, Inc.在提交给IETF
之RFC1321中之MD5 message-digest 算法。
*************************************************/
public class MD5 {
/* 下面这些S11-S44实际上是一个4*4之矩阵,在原始之C实现中是用#define 实现之,
这里把它们实现成为static final是表示了只读,切能在同一个进程空间内之多个
Instance间共享*/
static final int S11 = 7;
static final int S12 = 12;
static final int S13 = 17;
static final int S14 = 22;
static final int S21 = 5;
static final int S22 = 9;
static final int S23 = 14;
static final int S24 = 20;
static final int S31 = 4;
static final int S32 = 11;
static final int S33 = 16;
static final int S34 = 23;
static final int S41 = 6;
static final int S42 = 10;
static final int S43 = 15;
static final int S44 = 21;
static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 下面之三个成员是MD5计算过程中用到之3个核心数据,在原始之C实现中
被定义到MD5_CTX结构中
*/
private long[] state = new long[4]; // state (ABCD)
private long[] count = new long[2]; // number of bits, modulo 2^64 (lsb first)
private byte[] buffer = new byte[64]; // input buffer
/* digestHexStr是MD5之唯一一个公共成员,是最新一次计算结果之
16进制ASCII表示.
*/
public String digestHexStr;
/* digest,是最新一次计算结果之2进制内部表示,表示128bit之MD5值.
*/
private byte[] digest = new byte[16];
/*
getMD5ofStr是类MD5最主要之公共方法,入口参数是你想要进行MD5变换之字符串
返回之是变换完之结果,这个结果是从公共成员digestHexStr取得之.
*/
public String getMD5ofStr(String inbuf) {
md5Init();
md5Update(inbuf.getBytes(), inbuf.length());
md5Final();
digestHexStr = "";
for (int i = 0; i < 16; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr;
}
// 这是MD5这个类之标准构造函数,JavaBean要求有一个public之并且没有参数之构造函数
public MD5() {
md5Init();
return;
}
/* md5Init是一个初始化函数,初始化核心变量,装入标准之幻数 */
private void md5Init() {
count[0] = 0L;
count[1] = 0L;
///* Load magic initialization constants.
state[0] = 0x67452301L;
state[1] = 0xefcdab89L;
state[2] = 0x98badcfeL;
state[3] = 0x10325476L;
return;
}
/* F, G, H ,I 是4个基本之MD5函数,在原始之MD5之C实现中,由于它们是
简单之位运算,可能出于效率之考虑把它们实现成了宏,在java中,我们把它们
实现成了private方法,名字保持了原来C中之。 */
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));
}
/*
FF,GG,HH和II将调用F,G,H,I进行近一步变换
FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
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 = ((int) a << s) | ((int) a >>> (32 - 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 = ((int) a << s) | ((int) a >>> (32 - 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 = ((int) a << s) | ((int) a >>> (32 - 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 = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
/*
md5Update是MD5之主计算过程,inbuf是要变换之字节串,inputlen是长度,这个
函数由getMD5ofStr调用,调用之前需要调用md5init,因此把它设计成private之
*/
private void md5Update(byte[] inbuf, int inputLen) {
int i, index, partLen;
byte[] block = new byte[64];
index = (int)(count[0] >>> 3) & 0x3F;
// /* Update number of bits */
if ((count[0] += (inputLen << 3)) < (inputLen << 3))
count[1]++;
count[1] += (inputLen >>> 29);
partLen = 64 - index;
// Transform as many times as possible.
if (inputLen >= partLen) {
md5Memcpy(buffer, inbuf, index, 0, partLen);
md5Transform(buffer);
for (i = partLen; i + 63 < inputLen; i += 64) {
md5Memcpy(block, inbuf, 0, i, 64);
md5Transform (block);
}
index = 0;
} else
i = 0;
///* Buffer remaining input */
md5Memcpy(buffer, inbuf, index, i, inputLen - i);
}
/*
md5Final整理和填写输出结果
*/
private void md5Final () {
byte[] bits = new byte[8];
int index, padLen;
///* Save number of bits */
Encode (bits, count, 8);
///* Pad out to 56 mod 64.
index = (int)(count[0] >>> 3) & 0x3f;
padLen = (index < 56) ? (56 - index) : (120 - index);
md5Update (PADDING, padLen);
///* Append length (before padding) */
md5Update(bits, 8);
///* Store state in digest */
Encode (digest, state, 16);
}
/* md5Memcpy是一个内部使用之byte数组之块拷贝函数,从input之inpos开始把len长度之
字节拷贝到output之outpos位置开始
*/
private void md5Memcpy (byte[] output, byte[] input,
int outpos, int inpos, int len)
{
int i;
for (i = 0; i < len; i++)
output[outpos + i] = input[inpos + i];
}
/*
md5Transform是MD5核心变换程序,有md5Update调用,block是分块之原始字节
*/
private void md5Transform (byte block[]) {
long a = state[0], b = state[1], c = state[2], d = state[3];
long[] x = new long[16];
没有合适的资源?快使用搜索试试~ 我知道了~
news.zip_cms_cms java_cms java_java 内容管理
共234个文件
class:162个
java:46个
prefs:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 83 浏览量
2022-09-14
15:38:15
上传
评论
收藏 588KB ZIP 举报
温馨提示
这是一个内容管理系统(CMS)以MVC方式写出,没有使用框架
资源推荐
资源详情
资源评论
收起资源包目录
news.zip_cms_cms java_cms java_java 内容管理 (234个子文件)
IDCard.class 323KB
Py.class 177KB
DB.class 31KB
report.class 15KB
WEB.class 12KB
O_WEB.class 11KB
JFontDialog.class 10KB
MenuList.class 10KB
Pagination.class 9KB
UserPopedom.class 9KB
MD5.class 9KB
User.class 9KB
DBCon.class 8KB
ArticleOperateServlet.class 8KB
ArticleBean.class 8KB
PrintOptionDialog.class 8KB
O_DBCon.class 7KB
TableModel.class 7KB
ViewPrint.class 7KB
DocCombox$DatePopup.class 7KB
JPopupButton.class 6KB
O_DB.class 6KB
MenuManageListServlet.class 6KB
GroupableTableHeaderUI.class 5KB
ArticleMaglistServlet.class 5KB
DocCombox.class 5KB
ArticleAddServlet.class 5KB
UserAddServlet.class 5KB
DealString.class 5KB
ArticleTopicListServlet.class 5KB
JIpAddressField.class 5KB
ArticleAduitListServlet.class 5KB
ArticleRecycleListServlet.class 5KB
DTable.class 4KB
Encrypt.class 4KB
JStatusBar.class 4KB
ArticleEditServlet.class 4KB
TableContent.class 4KB
DocDate.class 4KB
MenuOperateServlet.class 4KB
PrintAction.class 4KB
CH.class 4KB
PrintDemo.class 4KB
DBCon$DBConnectionPool.class 4KB
AfficheManagerListServlet.class 4KB
DocCombox$DatePopup$JDayLable.class 4KB
opendb.class 4KB
UserMangerListServlet.class 3KB
MultiPagePopup.class 3KB
AfficheBean.class 3KB
mm.class 3KB
Mac.class 3KB
O_DBCon$DBConnectionPool.class 3KB
AddMenuServlet.class 3KB
DrawOut.class 3KB
ColumnGroup.class 3KB
JNumberField.class 3KB
GroupHeader.class 3KB
DTableUI.class 3KB
AfficheAddServlet.class 3KB
AfficheEditServlet.class 3KB
trytab.class 3KB
PrintString.class 3KB
PrintTabString.class 3KB
MenuBean.class 3KB
JPopupButton$PopupButtonListener.class 3KB
wjdhk.class 3KB
PrintContent.class 3KB
TopicBean.class 3KB
fileRW.class 3KB
DocNum.class 3KB
UserChangePasswordServlet.class 3KB
EditmenuServlet.class 3KB
Counter.class 3KB
UserEditServlet.class 3KB
tryGui.class 3KB
TestMain.class 3KB
WebMessBean.class 3KB
JFontComboBox.class 3KB
EnterEditMenuServlet.class 2KB
GroupableTableHeader.class 2KB
AfficheListServlet.class 2KB
rundb.class 2KB
FriendLinkBean.class 2KB
OpenSwingUtil.class 2KB
movedata.class 2KB
CheckUserPopedom.class 2KB
JDateField.class 2KB
AfficheOperateServlet.class 2KB
PreviewCanvas.class 2KB
WebParamAddServlet.class 2KB
TopicOperateServlet.class 2KB
Verify.class 2KB
myFileFilter.class 2KB
ColumnGroup$1.class 2KB
PrintAction$PageSetAction.class 2KB
UserOperaServlet.class 2KB
JStringField.class 2KB
PrintAction$PrintPageAction.class 2KB
PrintGridString.class 2KB
共 234 条
- 1
- 2
- 3
资源评论
小波思基
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- [大模型部署]在C# Winform中使用文心一言ERNIE-3.5 4K 聊天模型
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现.zip
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现+使用说明.zip
- 基于STM32单片机空气监测系统设计源码+详细文档+配套全部资料(毕业设计).zip
- rdf0412-kcu116-pcie-c-2019-1.zip(XILINX KCU116 源码)
- 基于C#语言的winform界面火车票订票系统(源码+实验报告)
- 【华为OD部分真题及讲解】华为OD部分真题及讲解
- 基于Python+Django的京东商品比价系统源码+全部资料(毕业设计).zip
- G460 G560 Z460 Z560的最新BIOS 2.18版(无白名单)
- MetaJUI v0.4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功