【fix sonar】AesEncryptUtil文件

This commit is contained in:
梁琦涛
2023-03-03 14:56:03 +08:00
parent dae3c13f5f
commit 55234ff460
@@ -11,6 +11,10 @@ import javax.crypto.spec.SecretKeySpec;
*/
public class AesEncryptUtil {
private AesEncryptUtil(){
}
//使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同!
private static String KEY = EncryptedString.key;
private static String IV = EncryptedString.iv;
@@ -23,7 +27,7 @@ public class AesEncryptUtil {
* @return 加密的结果
* @throws Exception
*/
public static String encrypt(String data, String key, String iv) throws Exception {
public static String encrypt(String data, String key, String iv) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding
@@ -60,7 +64,7 @@ public class AesEncryptUtil {
* @return 解密的结果
* @throws Exception
*/
public static String desEncrypt(String data, String key, String iv) throws Exception {
public static String desEncrypt(String data, String key, String iv) {
try {
byte[] encrypted1 = Base64.decode(data);
@@ -98,24 +102,4 @@ public class AesEncryptUtil {
public static String desEncrypt(String data) throws Exception {
return desEncrypt(data, KEY, IV);
}
// /**
// * 测试
// */
// public static void main(String args[]) throws Exception {
// String test1 = "sa";
// String test =new String(test1.getBytes(),"UTF-8");
// String data = null;
// String key = KEY;
// String iv = IV;
// // /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4=
// data = encrypt(test, key, iv);
// System.out.println("数据:"+test);
// System.out.println("加密:"+data);
// String jiemi =desEncrypt(data, key, iv).trim();
// System.out.println("解密:"+jiemi);
// }
}