File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
src/main/java/com/shy/day18 Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .shy .day18 ;
2
+
3
+ import java .security .MessageDigest ;
4
+ import java .security .NoSuchAlgorithmException ;
5
+
6
+ /**
7
+ * @ClassName MD5test
8
+ * @Author shy
9
+ * @Date 2020/11/6
10
+ **/
11
+ public class MD5test {
12
+ public static void main (String [] args ) {
13
+ String str = "qwer12345" ;
14
+ System .out .println ("加密前的密码:" + str );
15
+ String md5Str = createMD5 (str );
16
+ System .out .println ("加密后的密码:" + md5Str );
17
+ }
18
+ /**
19
+ * 创建给定字符串对应的加密后的字符串
20
+ */
21
+ public static String createMD5 (String str ) {
22
+ str = str + "shy" ;
23
+ try {
24
+ MessageDigest md = MessageDigest .getInstance ("MD5" );
25
+ md .update (str .getBytes ());
26
+ byte [] b = md .digest ();
27
+
28
+ int temp ;
29
+ StringBuilder sb = new StringBuilder ("" );
30
+ for (byte b1 : b ) {
31
+ temp = b1 ;
32
+ if (temp < 0 ) temp += 256 ;
33
+ if (temp < 16 ) sb .append ("0" );
34
+ sb .append (Integer .toHexString (temp ));
35
+ }
36
+ str = sb .toString ();
37
+ } catch (NoSuchAlgorithmException e ) {
38
+ e .printStackTrace ();
39
+ }
40
+ return str ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments