|
100精币
public static String encryptAES(String str, String str2, byte[ bArr) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException {
try {
IvParameterSpec ivParameterSpec = new IvParameterSpec(bArr);
SecretKeySpec secretKeySpec = new SecretKeySpec(str2.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(1, secretKeySpec, ivParameterSpec);
return Base64.encodeToString(cipher.doFinal(str.getBytes()), 0);
} catch (Exception e) {
return null;
}
}
|
|