|
|
@@ -7,10 +7,16 @@ import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.util.Base64;
|
|
|
|
|
|
public class PhoneUtil {
|
|
|
+ public static String AES_KEY = "AESAabCdeREssREA";
|
|
|
+ public static String OLD_KEY = "2c8d1a7f4e9b3c6ae6d5c4b3a291f8c9";
|
|
|
+
|
|
|
+ public static void setAesKey(String key) { AES_KEY = key; }
|
|
|
+ public static void setOldKey(String key) { OLD_KEY = key; }
|
|
|
+
|
|
|
public static String encryptPhone(String text) {
|
|
|
String encryptedText=null;
|
|
|
try {
|
|
|
- SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
|
|
|
+ SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES");
|
|
|
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
// Encryption
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
|
|
@@ -27,7 +33,7 @@ public class PhoneUtil {
|
|
|
public static String decryptPhone(String encryptedText) {
|
|
|
String text=null;
|
|
|
try {
|
|
|
- SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
|
|
|
+ SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES");
|
|
|
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
cipher.init(Cipher.DECRYPT_MODE, secretKey);
|
|
|
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText));
|
|
|
@@ -60,7 +66,7 @@ public class PhoneUtil {
|
|
|
if (encryptedText!=null&&encryptedText!="") {
|
|
|
if (encryptedText.length()>11){
|
|
|
try {
|
|
|
- SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
|
|
|
+ SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES");
|
|
|
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
cipher.init(Cipher.DECRYPT_MODE, secretKey);
|
|
|
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText));
|
|
|
@@ -81,7 +87,6 @@ public class PhoneUtil {
|
|
|
* @param text
|
|
|
* @return
|
|
|
*/
|
|
|
- private static String OLD_KEY = "2c8d1a7f4e9b3c6ae6d5c4b3a291f8c9";
|
|
|
public static String encryptPhoneOldKey(String text) {
|
|
|
String encryptedText=null;
|
|
|
try {
|