From b143c30501089ccedb4a15dbc62f8791129e2bde Mon Sep 17 00:00:00 2001 From: kerwincui <164770707@qq.com> Date: Thu, 25 Apr 2024 16:20:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=AF=86=E8=AE=A4=E8=AF=81=E6=94=AF?= =?UTF-8?q?=E6=8C=81JDK11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fastbee/iot/util/AESUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/springboot/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/util/AESUtils.java b/springboot/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/util/AESUtils.java index e42d99cb..e819ec5e 100644 --- a/springboot/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/util/AESUtils.java +++ b/springboot/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/util/AESUtils.java @@ -8,6 +8,7 @@ import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import java.security.MessageDigest; +import java.util.Base64; /** * @@ -38,7 +39,8 @@ public class AESUtils { cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); } byte[] encrypted = cipher.doFinal(plainText.getBytes("utf-8")); - String encryptedStr = new String(new BASE64Encoder().encode(encrypted)); + Base64.Encoder encoder = Base64.getEncoder(); + String encryptedStr = new String(encoder.encode(encrypted)); //此处使用BASE64做转码功能,同时能起到2次加密的作用。 return encryptedStr; } catch (Exception ex) { @@ -69,7 +71,8 @@ public class AESUtils { cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); } //先用base64解密 - byte[] encrypted = new BASE64Decoder().decodeBuffer(cipherText); + Base64.Decoder decoder = Base64.getDecoder(); + byte[] encrypted = decoder.decode(cipherText); try { byte[] original = cipher.doFinal(encrypted); String originalString = new String(original, "utf-8");