From aae0295ffdf3e3c9f995162713850fbdc8bb44ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Thu, 9 Mar 2023 12:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91AesEncryptUtil?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/encryption/AesEncryptUtil.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/encryption/AesEncryptUtil.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/encryption/AesEncryptUtil.java index 88a0e21c..745d7dbb 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/encryption/AesEncryptUtil.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/encryption/AesEncryptUtil.java @@ -16,8 +16,8 @@ public class AesEncryptUtil { } //使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同! - private static String KEY = EncryptedString.key; - private static String IV = EncryptedString.iv; + private static final String ENCRYPTED_KEY = EncryptedString.ENCRYPTED_KEY; + private static final String ENCRYPTED_IV = EncryptedString.ENCRYPTED_IV; /** * 加密方法 @@ -29,8 +29,8 @@ public class AesEncryptUtil { */ public static String encrypt(String data, String key, String iv) { try { - - Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding + //"算法/模式/补码方式"NoPadding PkcsPadding + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); int blockSize = cipher.getBlockSize(); byte[] dataBytes = data.getBytes(); @@ -75,8 +75,7 @@ public class AesEncryptUtil { cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec); byte[] original = cipher.doFinal(encrypted1); - String originalString = new String(original); - return originalString; + return new String(original); } catch (Exception e) { e.printStackTrace(); return null; @@ -90,7 +89,7 @@ public class AesEncryptUtil { * @throws Exception */ public static String encrypt(String data) { - return encrypt(data, KEY, IV); + return encrypt(data, ENCRYPTED_KEY, ENCRYPTED_IV); } /** @@ -100,6 +99,6 @@ public class AesEncryptUtil { * @throws Exception */ public static String desEncrypt(String data) { - return desEncrypt(data, KEY, IV); + return desEncrypt(data, ENCRYPTED_KEY, ENCRYPTED_IV); } }