库
create library pycryptodome
language plpythonu
from 's3://aws_python/library/pycryptodome/pycryptodome.zip'
credentials 'aws_iam_role'
region as 'aws-region';
功能
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;
我已经在python中测试了此代码,并且可以正常工作。 这里函数创建成功,但是当我使用test.aes_encrypt函数时 选择test.aes_encrypt('testing')然后抛出错误:
没有名为Crypto.Cipher._mode_ecb的模块。
请告知。
答案 0 :(得分:0)
您需要使用import Crypto
导入pycryptodome