一般的用户数据库是不用明文存入数据库的,像password这样的,都用md5加密一次之后才存入数据库的。
md5的转行代码:
1 import java.security.MessageDigest;
2 import java.security.NoSuchAlgorithmException;
3
4 public class MD5 {
5 private static String byte2Hex(byte b) {
6 int value = (b & 0x7F) + (b < 0 ? 0x80 : 0);
7 return (value < 0x10 ? "0" : "")
8 + Integer.toHexString(value).toLowerCase();
9 }
10
11 public static String MD5_32(String passwd) throws NoSuchAlgorithmException {
12 MessageDigest md5 = MessageDigest.getInstance("MD5");
13 StringBuffer strbuf = new StringBuffer();
14
15 md5.update(passwd.getBytes(), 0, passwd.length());
16 byte[] digest = md5.digest();
17 for (int i = 0; i < digest.length; i++) {
18 strbuf.append(byte2Hex(digest[i]));
19 }
20 return strbuf.toString();
21 }
22
23 public static void main(String[] args) {
24 try {
25 System.out.println(MD5_32("000"));
26 } catch (NoSuchAlgorithmException e) {
27 e.printStackTrace();
28 }
29 }
30 }