提问人:LeoG 提问时间:11/15/2023 更新时间:11/15/2023 访问量:31
Snowflake java UDF AES_256/GCM/NoPadding 不可用
Snowflake java UDF AES_256/GCM/NoPadding not available
问:
我有用Groovy编写的外部加密函数,并尝试使用Java在Snowflake中编写解密UDF。我收到错误。java.security.NoSuchAlgorithmException:在 java 上找不到任何支持“AES_256/GCM/NoPadding”的提供程序。Base/javax.crypto.Cipher.getInstance(Cipher.java:565) 在 function_handler_0//utility.decrypt(InlineCode.java:32)
下面是 java 函数:
private static final int KEY_LENGTH = 256;
private static final int ITERATION_COUNT = 10000; //65536;
private static final byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// private static GCMParameterSpec parameterSpec = new GCMParameterSpec(128, iv);
public static String decrypt(String strToDecrypt, String secretKey, String salt) {
try {
GCMParameterSpec parameterSpec = new GCMParameterSpec(128, iv);
byte[] encryptedData = Base64.getMimeDecoder().decode(strToDecrypt);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
KeySpec spec = new PBEKeySpec(secretKey.toCharArray(), salt.getBytes(), 65536, 256);
SecretKey tmp = factory.generateSecret(spec);
SecretKeySpec secretKeySpec = new SecretKeySpec(tmp.getEncoded(), "AES");
//cipher creation and decryption
Cipher cipher = Cipher.getInstance("AES_256/GCM/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, parameterSpec);
byte[] decryptedText = cipher.doFinal(encryptedData);
return new String(decryptedText, "UTF-8");
} catch (Exception e) {
// Handle the exception properly
e.printStackTrace();
return null;
}
}
解密功能在 Snowflake 之外工作正常。
有什么建议吗?
答: 暂无答案
评论
AES/GCM/NoPadding
AES_256
AES/GCM/NoPadding