Redshift UDF AES ENCRYPT - No module named Crypto.Cipher._mode_ecb

╄→гoц情女王★ 提交于 2020-02-26 02:42:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!