|
|
|
@@ -3,6 +3,7 @@ package com.xueyi.common.core.utils.core; |
|
|
|
import javax.crypto.Cipher; |
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
|
import java.security.Key; |
|
|
|
import java.util.Base64; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author yk |
|
|
|
@@ -25,15 +26,17 @@ public class CryptoUtil { |
|
|
|
byte[] ciphertext = cipher.doFinal(data.getBytes()); |
|
|
|
|
|
|
|
// 输出密文 |
|
|
|
return new String(ciphertext); |
|
|
|
return Base64.getEncoder().encodeToString(ciphertext); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String decrypt(String encryptedData) throws Exception { |
|
|
|
byte[] encryptedDataBytes = Base64.getDecoder().decode(encryptedData); |
|
|
|
Key k = new SecretKeySpec(DEFAULT_KEY.getBytes(), "AES"); |
|
|
|
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); |
|
|
|
cipher.init(Cipher.DECRYPT_MODE, k); |
|
|
|
byte[] decryptedBytes = cipher.doFinal(encryptedData.getBytes()); |
|
|
|
byte[] decryptedBytes = cipher.doFinal(encryptedDataBytes); |
|
|
|
//base64加密 |
|
|
|
return new String(decryptedBytes); |
|
|
|
} |
|
|
|
} |