【问题标题】:Redshift UDF AES ENCRYPT - No module named Crypto.Cipher._mode_ecbRedshift UDF AES ENCRYPT - 没有名为 Crypto.Cipher._mode_ecb 的模块
【发布时间】:2018-08-07 20:43:42
【问题描述】:

图书馆

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 的模块。

请指教。

【问题讨论】:

    标签: python amazon-redshift user-defined-functions


    【解决方案1】:

    您需要使用 import Crypto 导入 pycryptodome

    【讨论】:

    • 我尝试了import Crypto,但没有成功。 错误 nvalid operation: OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Trying '_raw_ecb.so': /rdsdbdata/user_lib/1/0/12345.zip/Crypto/Util/../Cipher/_raw_ecb.so: cannot open shared object file: Not a directory, Trying '_raw_ecbmodule.so': 请告知 这是库模块文件夹 - pycryptodome:文件夹 - 加密 init 文件夹 - 密码 AES _mode_ecb
    猜你喜欢
    • 2015-10-07
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2019-03-28
    • 2017-12-30
    相关资源
    最近更新 更多