问题
LIBRARY
create library pycryptodome
language plpythonu
from 's3://aws_python/library/pycryptodome/pycryptodome.zip'
credentials 'aws_iam_role'
region as 'aws-region';
FUNCTION
CREATE OR REPLACE FUNCTION test.aes_encrypt(input varchar(max))
RETURNS varchar(max)
STABLE
AS
'
if input is None:
return None
import pycryptodome
encrypt=True
secret_key = b''abcdefghijklmnop''
remainder = len(secret_key) % 16
modified_key = secret_key.ljust(len(secret_key) + (16 - remainder))[:32]
remainder = len(input) % 16
modified_text = input.ljust(len(input) + (16 - remainder))
cipher = pycryptodome.AES.new(modified_key, pycryptodome.AES.MODE_ECB)
return base64.b64encode(cipher.encrypt(modified_text)).strip()
'
LANGUAGE plpythonu;
I have tested this code in python and it worked correctly. Here function created successfully but when i use function test.aes_encrypt as select test.aes_encrypt('testing') then its throwing error:
No module named Crypto.Cipher._mode_ecb.
Please advise.
回答1:
You need import pycryptodome with import Crypto
来源:https://stackoverflow.com/questions/51735127/redshift-udf-aes-encrypt-no-module-named-crypto-cipher-mode-ecb