md在线加密
Ⅰ jsp中怎么实现MD5加密
写编写一个MD5加密工具类
通过import方式将MD5加密工具类引入到jsp中,然后使用MD5工具类进行加密
下面是MD5加密工具类代码
importjava.security.MessageDigest;
publicclassMD5Util{
(byteb[]){
StringBufferresultSb=newStringBuffer();
for(inti=0;i<b.length;i++)
resultSb.append(byteToHexString(b[i]));
returnresultSb.toString();
}
(byteb){
intn=b;
if(n<0)
n+=256;
intd1=n/16;
intd2=n%16;
returnhexDigits[d1]+hexDigits[d2];
}
publicstaticStringMD5Encode(Stringorigin,Stringcharsetname){
StringresultString=null;
try{
resultString=newString(origin);
MessageDigestmd=MessageDigest.getInstance("MD5");
if(charsetname==null||"".equals(charsetname))
resultString=byteArrayToHexString(md.digest(resultString
.getBytes()));
else
resultString=byteArrayToHexString(md.digest(resultString
.getBytes(charsetname)));
}catch(Exceptionexception){
}
returnresultString;
}
[]={"0","1","2","3","4","5",
"6","7","8","9","a","b","c","d","e","f"};
publicstaticvoidmain(String[]args){
Strings="appid=wxc7dac6b76548e969&attach=106&auth_code=130099732281083883&body=医泰天下远程会诊-20161019162200QCVV&mch_id=1393510702&nonce_str=&out_trade_no=20161019162200QCVV&time_expire=20161028192424&time_start=20161028182424&total_fee=1&key=";
System.out.println(MD5Encode(s,null));
}
}
Ⅱ MD5加密和哈希算法是什么
MD5(Message-Digest Algorithm 5,信息-摘要算法 5),用于确保信息传输完整一致。是计算机广泛使用的杂凑算法之一(又译摘要算法、哈希算法、Hash算法),主流编程语言普遍已有MD5实现。将数据(如英文字符串,汉字,文件等)运算为另一固定长度值是杂凑算法的基础原理,MD5的前身有MD2、MD3和MD4。 哈希算法将任意长度的二进制值映射为固定长度的较小二进制值,这个小的二进制值称为哈希值。哈希值是一段数据唯一且极其紧凑的数值表示形式。如果散列一段明文而且哪怕只更改该段落的一个字母,随后的哈希都将产生不同的值。要找到散列为同一个值的两个不同的输入,在计算上是不可能的,所以数据的哈希值可以检验数据的完整性。
哈希表是根据设定的哈希函数H(key)和处理冲突方法将一组关键字映象到一个有限的地址区间上,并以关键字在地址区间中的象作为记录在表中的存储位置,这种表称为哈希表或散列,所得存储位置称为哈希地址或散列地址。作为线性数据结构与表格和队列等相比,哈希表无疑是查找速度比较快的一种。
Ⅲ 谁可以告诉我md5加密原理
2004年,已经被山东大学的王小云教授破解了。
以下是她在国际密码学会上发表的破解原理论文。
Collisions for Hash Functions
Collisions for Hash Functions
MD4, MD5, HAVAL-128 and RIPEMD
Xiaoyun Wang1, Dengguo Feng2, Xuejia Lai3, Hongbo Yu1
The School of Mathematics and System Science, Shandong University, Jinan250100, China1
Institute of Software, Chinese Academy of Sciences, Beijing100080, China2
Dept. of Computer Science and Engineering, Shanghai Jiaotong University, Shanghai, China3
[email protected]
revised on August 17, 2004
1 Collisions for MD5
MD5 is the hash function designed by Ron Rivest [9] as a strengthened version of MD4 [8]. In 1993 Bert den
Boer and Antoon Bosselaers [1] found pseudo-collision for MD5 which is made of the same message with two
different sets of initial value. H. Dobbertin[3] found a free-start collision which consists of two different 512-bit
messages with a chosen initial value 0 V I .
ED BA x C B F x C B AC x A V I 763 4 0 D , 97 62 5 0 , 341042 3 0x B , 2375 12 0 : 0 0 0 0 0
Our attack can find many real collisions which are composed of two 1024-bit messages with the original
initial value 0 IV of MD5:
10325476 0 , 98 0 , 89 0 67452301 0 : 0 0 0 0 0 x D badcfe x C xefcdab ,B x A IV
) 0 , 2 ,..., 2 ,..., 2 , 0 , 0 , 0 , 0 ( , 31 15 31
1 1 C C M M
) 0 , 2 ,..., 2 ,..., 2 , 0 , 0 , 0 , 0 ( , 31 15 31
2 2 C C N N i i
(non-zeros at position 4,11 and 14)
such that
) , ( 5 ) , ( 5 i i N M MD N M MD .
On IBM P690, it takes about one hour to find such M and M , after that, it takes only 15 seconds to 5
minutes to find i N and i N , so that ) , ( i N M and ) , ( i N M will proce the same hash same value. Moreover,
our attack works for any given initial value.
The following are two pairs of 1024-bit messages procing collisions, the two examples have the same 1-st
half 512 bits.
M
2dd31d1 c4eee6c5 69a3d69 5cf9af98 87b5ca2f ab7e4612 3e580440 897ffbb8
634ad55 2b3f409 8388e483 5a417125 e8255108 9fc9cdf7 f2bd1dd9 5b3c3780
X1
N1
d11d0b96 9c7b41dc f497d8e4 d555655a c79a7335 cfdebf0 66f12930 8fb109d1
797f2775 eb5cd530 baade822 5c15cc79 ddcb74ed 6dd3c55f d80a9bb1 e3a7cc35
M0
2dd31d1 c4eee6c5 69a3d69 5cf9af98 7b5ca2f ab7e4612 3e580440 897ffbb8
634ad55 2b3f409 8388e483 5a41f125 e8255108 9fc9cdf7 72bd1dd9 5b3c3780
X1
N1
d11d0b96 9c7b41dc f497d8e4 d555655a 479a7335 cfdebf0 66f12930 8fb109d1
797f2775 eb5cd530 baade822 5c154c79 ddcb74ed 6dd3c55f 580a9bb1 e3a7cc35
H 9603161f f41fc7ef 9f65ffbc a30f9dbf
M
2dd31d1 c4eee6c5 69a3d69 5cf9af98 87b5ca2f ab7e4612 3e580440 897ffbb8
634ad55 2b3f409 8388e483 5a417125 e8255108 9fc9cdf7 f2bd1dd9 5b3c3780
X2
N2
313e82d8 5b8f3456 d4ac6dae c619c936 b4e253dd fd03da87 6633902 a0cd48d2
42339fe9 e87e570f 70b654ce 1e0da880 bc2198c6 9383a8b6 2b65f996 702af76f
M0
2dd31d1 c4eee6c5 69a3d69 5cf9af98 7b5ca2f ab7e4612 3e580440 897ffbb8
634ad55 2b3f409 8388e483 5a41f125 e8255108 9fc9cdf7 72bd1dd9 5b3c3780
313e82d8 5b8f3456 d4ac6dae c619c936 34e253dd fd03da87 6633902 a0cd48d2
42339fe9 e87e570f 70b654ce 1e0d2880 bc2198c6 9383a8b6 ab65f996 702af76f
H 8d5e7019 6324c015 715d6b58 61804e08
Table 1 Two pairs of collisions for MD5
2 Collisions for HAVAL-128
HAVAL is proposed in [10]. HAVAL is a hashing algorithm that can compress messages of any length in 3,4
or 5 passes and proce a fingerprint of length 128, 160, 192 or 224 bits.
Attack on a reced version for HAVAL was given by P. R. Kasselman and W T Penzhorn [7], which
consists of last rounds for HAVAL-128. We break the full HAVAL-128 with only about the 26 HAVAL
computations. Here we give two examples of collisions of HAVAL-128, where
) 0 ,..., 0 , 2 ,.... 2 , 0 , 0 , 0 , 2 ( , 8 12 1 i i i C C M M
with non-zeros at position 0,11,18, and 31 ,... 2 , 1 , 0 i , such that ) ( ) ( M HAVAL M HAVAL .
M1
6377448b d9e59f18 f2aa3cbb d6cb92ba ee544a44 879fa576 1ca34633 76ca5d4f
a67a8a42 8d3adc8b b6e3d814 5630998d 86ea5dcd a739ae7b 54fd8e32 acbb2b36
38183c9a b67a9289 c47299b2 27039ee5 dd555e14 839018d8 aabbd9c9 d78fc632
fff4b3a7 40000096 7f466aac fffffbc0 5f4016d2 5f4016d0 12e2b0 f4307f87
M1
6377488b d9e59f18 f2aa3cbb d6cb92ba ee544a44 879fa576 1ca34633 76ca5d4f
a67a8a42 8d3adc8b b6e3d814 d630998d 86ea5dcd a739ae7b 54fd8e32 acbb2b36
38183c9a b67a9289 c47299ba 27039ee5 dd555e14 839018d8 aabbd9c9 d78fc632
fff4b3a7 40000096 7f466aac fffffbc0 5f4016d2 5f4016d0 12e2b0 f4307f87
H 95b5621c ca62817a a48dacd8 6d2b54bf
M2
6377448b d9e59f18 f2aa3cbb d6cb92ba ee544a44 879fa576 1ca34633 76ca5d4f
a67a8a42 8d3adc8b b6e3d814 5630998d 86ea5dcd a739ae7b 54fd8e32 acbb2b36
38183c9a b67a9289 c47299b2 27039ee5 dd555e14 839018d8 aabbd9c9 d78fc632
fff4b3a7 40000096 7f466aac fffffbc0 5f4016d2 5f4016d0 12e2b0 f5b16963
6377488b d9e59f18 f2aa3cbb d6cb92ba ee544a44 879fa576 1ca34633 76ca5d4f
a67a8a42 8d3adc8b b6e3d814 d630998d 86ea5dcd a739ae7b 54fd8e32 acbb2b36
38183c9a b67a9289 c47299ba 27039ee5 dd555e14 839018d8 aabbd9c9 d78fc632
fff4b3a7 40000096 7f466aac fffffbc0 5f4016d2 5f4016d0 12e2b0 f5b16963
H b0e99492 d64eb647 5149ef30 4293733c
Table 2 Two pairs of collision, where i=11 and these two examples differ only at the last word
3 Collisions for MD4
MD4 is designed by R. L. Rivest[8] . Attack of H. Dobbertin in Eurocrypto'96[2] can find collision with
probability 1/222. Our attack can find collision with hand calculation, such that
) 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 2 , 2 , 0 ( , 16 31 28 31 C C M M
and ) ( 4 ) ( 4 M MD M MD .
M1
4d7a9c83 56cb927a b9d5a578 57a7a5ee de748a3c dcc366b3 b683a020 3b2a5d9f
c69d71b3 f9e99198 d79f805e a63bb2e8 45dd8e31 97e31fe5 2794bf08 b9e8c3e9
M1
4d7a9c83 d6cb927a 29d5a578 57a7a5ee de748a3c dcc366b3 b683a020 3b2a5d9f
c69d71b3 f9e99198 d79f805e a63bb2e8 45dc8e31 97e31fe5 2794bf08 b9e8c3e9
H 5f5c1a0d 71b36046 1b5435da 9b0d807a
M2
4d7a9c83 56cb927a b9d5a578 57a7a5ee de748a3c dcc366b3 b683a020 3b2a5d9f
c69d71b3 f9e99198 d79f805e a63bb2e8 45dd8e31 97e31fe5 f713c240 a7b8cf69
4d7a9c83 d6cb927a 29d5a578 57a7a5ee de748a3c dcc366b3 b683a020 3b2a5d9f
c69d71b3 f9e99198 d79f805e a63bb2e8 45dc8e31 97e31fe5 f713c240 a7b8cf69
H e0f76122 c429c56c ebb5e256 b809793
Table 3 Two pairs of collisions for MD4
4 Collisions for RIPEMD
RIPEMD was developed for the RIPE project (RACE Integrrity Primitives Evalustion, 1988-1992). In
1995, H. Dobbertin proved that the reced version RIPEMD with two rounds is not collision-free[4]. We show
that the full RIPEMD also isnOt collision-free. The following are two pairs of collisions for RIPEMD:
) 2 , 0 , 0 , 0 , 0 , 2 2 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 ( , 31 31 18 20 ' C C M M i i
M1
579faf8e 9ecf579 574a6aba 78413511 a2b410a4 ad2f6c9f b56202c 4d757911
bdeaae7 78bc91f2 47bc6d7d 9abdd1b1 a45d2015 817104ff 264758a8 61064ea5
M1
579faf8e 9ecf579 574a6aba 78513511 a2b410a4 ad2f6c9f b56202c 4d757911
bdeaae7 78bc91f2 c7c06d7d 9abdd1b1 a45d2015 817104ff 264758a8 e1064ea5
H 1fab152 1654a31b 7a33776a 9e968ba7
M2
579faf8e 9ecf579 574a6aba 78413511 a2b410a4 ad2f6c9f b56202c 4d757911
bdeaae7 78bc91f2 47bc6d7d 9abdd1b1 a45d2015 a0a504ff b18d58a8 e70c66b6
579faf8e 9ecf579 574a6aba 78513511 a2b410a4 ad2f6c9f b56202c 4d757911
bdeaae7 78bc91f2 c7c06d7d 9abdd1b1 a45d2015 a0a504ff b18d58a8 670c66b6
H 1f2c159f 569b31a6 dfcaa51a 25665d24
Table 4 The collisions for RIPEMD
5 Remark
Besides the above hash functions we break, there are some other hash functions not having ideal security. For
example, collision of SHA-0 [6] can be found with about 240 computations of SHA-0 algorithms, and a collision
for HAVAL-160 can be found with probability 1/232.
Note that the messages and all other values in this paper are composed of 32-bit words, in each 32-bit word
the most left byte is the most significant byte.
1 B. den Boer, Antoon Bosselaers, Collisions for the Compression Function of MD5, Eurocrypto,93.
2 H. Dobbertin, Cryptanalysis of MD4, Fast Software Encryption, LNCS 1039, D. , Springer-Verlag, 1996.
3 H. Dobbertin, Cryptanalysis of MD5 compress, presented at the rump session of EurocrZpt'96.
4 Hans Dobbertin, RIPEMD with Two-round Compress Function is Not Collision-Free, J. Cryptology 10(1),
1997.
5 H. Dobbertin, A. Bosselaers, B. Preneel, "RIPMEMD-160: A Strengthened Version of RIPMMD," Fast
Software EncrZption, LNCS 1039, D.Gollmann, Ed., Springer-Verlag, 1996, pp. 71-82.
6 FIPS 180-1, Secure hash standard, NIST, US Department of Commerce, Washington D. C., April 1995.
7 P. R. Kasselman, W T Penzhorn , Cryptananlysis od reced version of HAVAL, Vol. 36, No. 1, Electronic
Letters, 2000.
8 R. L. Rivest, The MD4 Message Digest Algorithm, Request for Comments (RFC)1320, Internet Activities
Board, Internet Privacy Task Force, April 1992.
9 R. L Rivest, The MD5 Message Digest Algorithm, Request for Comments (RFC)1321, Internet Activities
Board, Internet PrivacZ Task Force, April 1992.3RIPEMD-1281
10 Y. Zheng, J. Pieprzyk, J. Seberry, HAVAL--A One-way Hashing Algorithm with Variable Length of Output,
Auscrypto'92.
Ⅳ Md5如何通过四个参数进行加密
你好,你先将abcd连接在一起,然后下面是加密的函数
def md5_passwd(str,salt='123456'):
#satl是盐值,默认是123456
str=str+salt
import hashlib
md = hashlib.md5() # 构造一个md5对象
md.update(str.encode())
res = md.hexdigest()
return res
输入是abcd的连接字符串
Ⅳ 如何在linux使用md5对其进行加密
这里以字符串123456为例子,它的md5密文值为:
这里以1.txt为需要被加密的文件。
一、 用oppnssl md5 加密字符串和文件的方法。
1. oppnssl md5 加密字符串的方法
a.手动输入命令及过程如下:
#openssl //在终端中输入openssl后回车。
OpenSSL> md5 //输入md5后回车
123456 //接着输入123456,不要输入回车。然后按3次ctrl+d。
123456 //123456后面的就是密文了
解释:为何在输入123456后不回车呢?
是因为openssl默认会把回车符当做要加密的字符串中的一个字符,所以得到的结果不同。如果你输入123456后回车,在按2次ctrl+d。得到的结果是:
OpenSSL> md5
123456
//因为openssl不忽略回车符导致的
b.或者直接用管道命令
# echo -n 123456 | openssl md5 //必须要有-n参数,否则就不是这个结果了。
解释:为何要加-n这个参数?
-n就表示不输入回车符,这样才能得到正确的结果。如果你不加-n,那么结果和前面说的一样为:
//因为openssl不忽略回车符导致的
2.用openssl加密文件。
#openssl md 5 -in 1.txt
##################################################3
Openssl其他相关加密的命令参数:引自:实用命令:利用openssl进行BASE64编码解码、md5/sha1摘要、AES/DES3加密解密 收藏
一. 利用openssl命令进行BASE64编码解码(base64 encode/decode)
1. BASE64编码命令
对字符串‘abc’进行base64编码:
# echo abc | openssl base64
YWJjCg== (编码结果)
如果对一个文件进行base64编码(文件名t.txt):
# openssl base64 -in t.txt
2. BASE64解码命令
求base64后的字符串‘YWJjCg==’的原文:
# echo YWJjCg== | openssl base64 -d
abc (解码结果)
如果对一个文件进行base64解码(文件名t.base64):
# openssl base64 -d -in t.base64
二. 利用openssl命令进行md5/sha1摘要(digest)
1. 对字符串‘abc’进行md5摘要计算:echo abc | openssl md5
若对某文件进行md5摘要计算:openssl md5 -in t.txt
2. 对字符串‘abc’进行sha1摘要计算:echo abc | openssl sha1
若对某文件进行sha1摘要计算:openssl sha1 -in t.txt
三. 利用openssl命令进行AES/DES3加密解密(AES/DES3 encrypt/decrypt)
对字符串‘abc’进行aes加密,使用密钥123,输出结果以base64编码格式给出:
# echo abc | openssl aes-128-cbc -k 123 -base64
U2FsdGVkX18ynIbzARm15nG/JA2dhN4mtiotwD7jt4g= (结果)
对以上结果进行解密处理:
# echo U2FsdGVkX18ynIbzARm15nG/JA2dhN4mtiotwD7jt4g= | openssl aes-128-cbc -d -k 123 -base64
abc (结果)
若要从文件里取原文(密文)进行加密(解密),只要指定 -in 参数指向文件名就可以了。
进行des3加解密,只要把命令中的aes-128-cbc换成des3就可以了。
注:只要利用openssl help就可以看到更多的安全算法了。
###############################################
二、 利用php的md5函数加密字符串
#touch a.php //创建a.php文件
#vi a.php //用vi 编辑a.php文件
将<?php echo md5(123456); ?>输入进去后保存
#php a.php //运行a.php文件
显示:
三、 利用md5sum命令
A.在linux或Unix上,md5sum是用来计算和校验文件报文摘要的工具程序。一般来说,安装了Linux后,就会有md5sum这个工具,直接在命令行终端直接运行。可以用下面的命令来获取md5sum命令帮助 man md5sum
#md5sum –help
有个提示:“With no FILE, or when FILE is -, read standard input.”翻译过来就是“如果没有输入文件选项或者文件选项为 - ,则从标砖读取输入内容”,即可以直接从键盘读取字符串来加密。
利用md5sum加密字符串的方法
# md5sum //然后回车
123456 //输入123456.然后按两次ctrl+d.
显示:
123456 红色代表加密后的值
还可以用管道命令:
#echo -n '123123' | md5sum
或者写成md5加密脚本,名字叫md5.sh,
将以下内容复制进脚本里:
#!/bin/bash
echo -n $1 | md5sum | awk '{print $1}'
保存后,给脚本执行权限。
#sh md5.sh 123456
显示:
B.其实也可以将文本放入文本文件,然后用md5sum 加密改文本,也可以得到字符串加密的值。过程如下:
#touch a.txt
#echo -n 123456 > a.txt //将123456写进文本文件,不能丢了 –n参数,避免回车符干扰
#md5sum a.txt
显示: a.txt
ctrl+d有两个含义:
一是向程序发送文件输入结束符EOF。
二是向程序发送exit退出指令。程序收到信号后具体动作是结束输入、然后等待,还是直接退出,那就要看该程序捕获信号后是如何操作的了。
md5sum属于第一个含义。两次strl+d了,第一次读取EOF指令,再次捕获就会当成exit指令。而shell一类的程序,会直接把ctrl+d解析为退出指令。