【fix sonar】AesEncryptUtil文件
This commit is contained in:
+7
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user