Redshift Python encrypt/decrypt UDF Error - String contains invalid or unsupported UTF8 codepoints

匿名 (未验证) 提交于 2019-12-03 01:03:01

问题:

I want to create the below encrypt and decrypt UDF's in Redshift.

Library:

create library pyaes language plpythonu from 's3://aws_python/library/pyaes/pyaes.zip' credentials 'aws-role' region as 'aws-region'; 

Encrypt:

CREATE OR REPLACE FUNCTION test.aes_encrypt(input varchar(max)) RETURNS varchar(max) AS '    if input is None:         return None     import pyaes     key = ''abcdefghijklopoo''     aes = pyaes.AESModeOfOperationCTR(key)     encrypted_msg = aes.encrypt(input)     return encrypted_msg ' LANGUAGE plpythonu STABLE; 

Tried with below options as well:

encrypted_msg = aes.encrypt(input.encode("utf8"))   key = key.encode('utf-8') 

Decrypt:

CREATE OR REPLACE FUNCTION test.aes_decrypt(encrypted_msg varchar(max)) RETURNS varchar(max) AS  '     if encrypted_msg is None or len(str(encrypted_msg)) == 0:        return None     import pyaes     key = ''abcdefghijklopoo''     aes = pyaes.AESModeOfOperationCTR (key)     decrypted_msg = aes.decrypt(encrypted_msg).decode("utf8")     return decrypted_msg ' LANGUAGE plpythonu STABLE; 

select aes_encrypt('Testing'); select aes_decrypt('');

But it's throwing below error:

Error: Invalid operation: String contains invalid or unsupported UTF8 codepoints. Bad UTF8 hex sequence: d5 fc (error 4);

Please advise. Thanks in advance.

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