clean code

This commit is contained in:
chenxudong 2025-05-15 13:47:38 +08:00
parent 82ef0063f7
commit c6dcd99afb
1 changed files with 0 additions and 52 deletions

View File

@ -6,10 +6,8 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import javax.crypto.*; import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.Security; import java.security.Security;
/** /**
@ -21,56 +19,6 @@ import java.security.Security;
*/ */
public class AESUtils { public class AESUtils {
/**
* <p>Discription:[加密]</p>
* Created on 2022/07/06 10:52
*
* @param content 明文 用JSON.toJSONString(Map<String, String> map)转换的json字符串
* @param key 加解密规则 访客系统提供key
* @return String 密文
*/
public static String ecodes(String content, String key) {
if (content == null || content.length() < 1) {
return null;
}
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(key.getBytes());
kgen.init(128, random);
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
byte[] byteRresult = cipher.doFinal(byteContent);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteRresult.length; i++) {
String hex = Integer.toHexString(byteRresult[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
/** /**
* 前端使用ECB后端解密方法 * 前端使用ECB后端解密方法
* *