Encrypt.java
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.teplot.common;
import com.jfinal.kit.HashKit;
import com.jfinal.kit.StrKit;
/**
* Depiction: 密码加密
* <p>
* Modify:
* <p>
* Author: Kevin Lynn
* <p>
* Create Date:2017年6月1日 上午12:31:18
*
*/
public class Encrypt {
public static void main(String[] args) {
System.out.println(Encrypt.encrypt("west", HashKit.sha256("000000")));
}
/**
*
* @param username
* 用户名
* @param password
* 对密码原串sha256之后的密文
* @return
*/
public static String encrypt(String username, String password) {
if (StrKit.isBlank(username)) {
throw new RuntimeException("the username is blank");
}
if (StrKit.isBlank(password)) {
throw new RuntimeException("the password is blank");
}
// if (username.length() < 5) {
// throw new RuntimeException("the username is too short");
// }
//
// if (password.length() < 64) {
// throw new RuntimeException("the password is not sha256");
// }
String salt = HashKit.md5(username).substring(2, 10);
return HashKit.sha256(salt + password);
}
}