|
@@ -13,6 +13,8 @@ import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.Base64;
|
|
import java.util.Base64;
|
|
|
|
|
|
|
|
public class AESUtil {
|
|
public class AESUtil {
|
|
|
|
|
+ private static final String USERKEY = "49PBou+TREIOzSHj";
|
|
|
|
|
+ private static final String USERIV = "5lDsNRe&UduJ97uS";
|
|
|
private static final String KEY = "dmngJmmO+9GMw+tu";
|
|
private static final String KEY = "dmngJmmO+9GMw+tu";
|
|
|
private static final String IV = "sanXyqhk8+U7LPP4";
|
|
private static final String IV = "sanXyqhk8+U7LPP4";
|
|
|
public static String decrypt(String encryptedText)
|
|
public static String decrypt(String encryptedText)
|
|
@@ -29,4 +31,19 @@ public class AESUtil {
|
|
|
byte[] decryptedBytes = cipher.doFinal(encryptedData);
|
|
byte[] decryptedBytes = cipher.doFinal(encryptedData);
|
|
|
return new String(decryptedBytes, StandardCharsets.UTF_8).trim(); // 去除末尾空格
|
|
return new String(decryptedBytes, StandardCharsets.UTF_8).trim(); // 去除末尾空格
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static String decryptUser(String encryptedText)
|
|
|
|
|
+ throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException,
|
|
|
|
|
+ IllegalBlockSizeException, BadPaddingException {
|
|
|
|
|
+ byte[] encryptedData = Base64.getDecoder().decode(encryptedText);
|
|
|
|
|
+
|
|
|
|
|
+ SecretKeySpec secretKeySpec = new SecretKeySpec(USERKEY.getBytes(StandardCharsets.UTF_8), "AES");
|
|
|
|
|
+ IvParameterSpec ivParameterSpec = new IvParameterSpec(USERIV.getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
+
|
|
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); // 使用CBC模式和PKCS5Padding填充
|
|
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
|
|
|
|
|
+
|
|
|
|
|
+ byte[] decryptedBytes = cipher.doFinal(encryptedData);
|
|
|
|
|
+ return new String(decryptedBytes, StandardCharsets.UTF_8).trim(); // 去除末尾空格
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|