【fix sonar】AesEncryptUtil文件
This commit is contained in:
+7
-8
@@ -16,8 +16,8 @@ public class AesEncryptUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同!
|
//使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同!
|
||||||
private static String KEY = EncryptedString.key;
|
private static final String ENCRYPTED_KEY = EncryptedString.ENCRYPTED_KEY;
|
||||||
private static String IV = EncryptedString.iv;
|
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) {
|
public static String encrypt(String data, String key, String iv) {
|
||||||
try {
|
try {
|
||||||
|
//"算法/模式/补码方式"NoPadding PkcsPadding
|
||||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding
|
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
|
||||||
int blockSize = cipher.getBlockSize();
|
int blockSize = cipher.getBlockSize();
|
||||||
|
|
||||||
byte[] dataBytes = data.getBytes();
|
byte[] dataBytes = data.getBytes();
|
||||||
@@ -75,8 +75,7 @@ public class AesEncryptUtil {
|
|||||||
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
|
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
|
||||||
|
|
||||||
byte[] original = cipher.doFinal(encrypted1);
|
byte[] original = cipher.doFinal(encrypted1);
|
||||||
String originalString = new String(original);
|
return new String(original);
|
||||||
return originalString;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@@ -90,7 +89,7 @@ public class AesEncryptUtil {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static String encrypt(String data) {
|
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
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static String desEncrypt(String data) {
|
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