Redshift UDF AES ENCRYPT-没有名为Crypto.Cipher._mode_ecb的模块 [英] Redshift UDF AES ENCRYPT - No module named Crypto.Cipher._mode_ecb

查看:186
本文介绍了Redshift UDF AES ENCRYPT-没有名为Crypto.Cipher._mode_ecb的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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')然后抛出错误:

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:

没有名为Crypto.Cipher._mode_ecb的模块.

No module named Crypto.Cipher._mode_ecb.

请告知.

推荐答案

您需要使用import Crypto

这篇关于Redshift UDF AES ENCRYPT-没有名为Crypto.Cipher._mode_ecb的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆