update 格式化PasswordUtil.java
This commit is contained in:
+7
-24
@@ -75,24 +75,18 @@ public class PasswordUtil {
|
||||
|
||||
/**
|
||||
* 加密明文字符串
|
||||
*
|
||||
* @param plaintext
|
||||
* 待加密的明文字符串
|
||||
* @param password
|
||||
* 生成密钥时所使用的密码
|
||||
* @param salt
|
||||
* 盐值
|
||||
* @param plaintext 待加密的明文字符串
|
||||
* @param password 生成密钥时所使用的密码
|
||||
* @param salt 盐值
|
||||
* @return 加密后的密文字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encrypt(String plaintext, String password, String salt) {
|
||||
|
||||
Key key = getPBEKey(password);
|
||||
byte[] encipheredData = null;
|
||||
PBEParameterSpec parameterSpec = new PBEParameterSpec(salt.getBytes(), ITERATIONCOUNT);
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(ALGORITHM);
|
||||
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key, parameterSpec);
|
||||
//update-begin-author:sccott date:20180815 for:中文作为用户名时,加密的密码windows和linux会得到不同的结果 gitee/issues/IZUD7
|
||||
encipheredData = cipher.doFinal(plaintext.getBytes("utf-8"));
|
||||
@@ -111,24 +105,18 @@ public class PasswordUtil {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encrypt(String plaintext) {
|
||||
|
||||
return encrypt(plaintext, ALGORITHM, Salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密密文字符串
|
||||
*
|
||||
* @param ciphertext
|
||||
* 待解密的密文字符串
|
||||
* @param password
|
||||
* 生成密钥时所使用的密码(如需解密,该参数需要与加密时使用的一致)
|
||||
* @param salt
|
||||
* 盐值(如需解密,该参数需要与加密时使用的一致)
|
||||
* @param ciphertext 待解密的密文字符串
|
||||
* @param password 生成密钥时所使用的密码(如需解密,该参数需要与加密时使用的一致)
|
||||
* @param salt 盐值(如需解密,该参数需要与加密时使用的一致)
|
||||
* @return 解密后的明文字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decrypt(String ciphertext, String password, String salt) {
|
||||
|
||||
Key key = getPBEKey(password);
|
||||
byte[] passDec = null;
|
||||
PBEParameterSpec parameterSpec = new PBEParameterSpec(salt.getBytes(), ITERATIONCOUNT);
|
||||
@@ -139,7 +127,6 @@ public class PasswordUtil {
|
||||
|
||||
passDec = cipher.doFinal(hexStringToBytes(ciphertext));
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
@@ -149,12 +136,9 @@ public class PasswordUtil {
|
||||
return new String(passDec);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义解密密文字符串
|
||||
*
|
||||
* @param ciphertext
|
||||
* 待解密的密文字符串
|
||||
* @param ciphertext 待解密的密文字符串
|
||||
* @return 解密后的明文字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -164,7 +148,6 @@ public class PasswordUtil {
|
||||
}else {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user