项目使用sonar后,提示AES加密不安全,推荐使用AES/GCM/NoPadding,调整后的完整代码
private static final String KEY_ALGORITHM_AES = "AES";
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/GCM/NoPadding";
private static final String CHARSET = "UTF-8";
/**
* 加密
* @param content
* @param encryptPass
* @return
*/
public static String aesEncrypt(String content, String encryptPass) {
try {
byte[] iv = new byte[12];
SecureRandom secureRandom = new SecureRandom();
secureRandom.nextBytes(iv);
byte[] contentBytes = content.getBytes(CHARSET);
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM