password entity
Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
parent
d233fdedbe
commit
f0b471db37
Binary file not shown.
36
project2/src/main/java/cyou/chenx221/pojo/Password.java
Normal file
36
project2/src/main/java/cyou/chenx221/pojo/Password.java
Normal file
@ -0,0 +1,36 @@
|
||||
package cyou.chenx221.pojo;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class Password {
|
||||
private String password;
|
||||
private String encryptedPassword;
|
||||
|
||||
public Password() {
|
||||
}
|
||||
|
||||
public Password(String password) throws NoSuchAlgorithmException {
|
||||
encryptedPassword = encryptPassword(password);
|
||||
}
|
||||
|
||||
private String encryptPassword(String password) throws NoSuchAlgorithmException {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = digest.digest(password.getBytes());
|
||||
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
public String getEncryptedPassword() {
|
||||
return encryptedPassword;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user