-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
赵栩彬
committed
Nov 22, 2019
1 parent
1bc0d51
commit 4bcc929
Showing
6 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package site.yan.key; | ||
|
||
import site.yan.key.securtiy.Secrey; | ||
|
||
/** | ||
* Create in 2019/11/22 9:31 by Zhao Xubin. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package site.yan.key.securtiy; | ||
|
||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
/** | ||
* Create in 2019/11/22 11:25 by Zhao Xubin. | ||
*/ | ||
public class MD5Core { | ||
public static String getMD5(String plainText) { | ||
try { | ||
MessageDigest md = MessageDigest.getInstance("MD5");//获取MD5实例 | ||
md.update(plainText.getBytes());//此处传入要加密的byte类型值 | ||
byte[] digest = md.digest();//此处得到的是md5加密后的byte类型值 | ||
|
||
/* | ||
下边的运算就是自己添加的一些二次小加密,记住这个千万不能弄错乱, | ||
否则在解密的时候,你会发现值不对的(举例:在注册的时候加密方式是一种, | ||
在我们登录的时候是不是还需要加密它的密码然后和数据库的进行比对,但是 | ||
最后我们发现,明明密码对啊,就是打不到预期效果,这时候你就要想一下,你是否 | ||
有改动前后的加密方式) | ||
*/ | ||
int i; | ||
StringBuilder sb = new StringBuilder(); | ||
for (int offset = 0; offset < digest.length; offset++) { | ||
i = digest[offset]; | ||
if (i < 0) | ||
i += 256; | ||
if (i < 16) | ||
sb.append(0); | ||
sb.append(Integer.toHexString(i));//通过Integer.toHexString方法把值变为16进制 | ||
} | ||
return sb.toString().substring(0, 24);//从下标0开始,length目的是截取多少长度的值 | ||
} catch (NoSuchAlgorithmException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(getMD5("1234")); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters