英文:
Databricks aes_decrypt() not giving original text for string encrypted using aes_encrypt()
问题
我有一些数据需要加密,我想使用内置在 Databricks 中的 aes_encrypt 函数。但是,我无法成功地使用 Databricks 中的 aes_encrypt() 和 aes_decrypt() 函数加密然后恢复原始文本。
一个示例如下。
我需要做什么才能恢复原始文本?
**查询:**
select
'test' as original_text,
aes_encrypt('test','foobarfoobarfoobarfoobar') as encrypted,
aes_decrypt(aes_encrypt('test','foobarfoobarfoobarfoobar'), 'foobarfoobarfoobarfoobar') as decrypted
**输出:**
original_text encrypted decrypted
test shj898e14ahsu3yNcuNiI+iaVy4ajc5NBnReC08GjIA= dGVzdA==
英文:
I have some data that I need to encrypt and I'd like to use the aes_encrypt function built into Databricks. However, I'm unable to successfully encrypt and then get back the original text using the aes_encrypt() and aes_decrypt() functions build into Databricks.
An example is given below.
What do I need to do to get back the original text?
Query:
select
'test' as original_text,
aes_encrypt('test','foobarfoobarfoobarfoobar') as encrypted,
aes_decrypt(aes_encrypt('test','foobarfoobarfoobarfoobar'), 'foobarfoobarfoobarfoobar') as decrypted
Output:
original_text encrypted decrypted
test shj898e14ahsu3yNcuNiI+iaVy4ajc5NBnReC08GjIA= dGVzdA==
答案1
得分: 0
这篇帖子很有帮助:
https://docs.databricks.com/sql/language-manual/functions/aes_decrypt.html
这导致了这个解决方案:
-- 这个可行
select
'test' as original_text,
base64(aes_encrypt('test','foobarfoobarfoobarfoobar')) as encrypted,
cast(aes_decrypt(unbase64(base64(aes_encrypt('test','foobarfoobarfoobarfoobar'))), 'foobarfoobarfoobarfoobar') as string) as decrypted;
英文:
This post was helpful:
https://docs.databricks.com/sql/language-manual/functions/aes_decrypt.html
Which leads to this solution:
-- this works
select
'test' as original_text,
base64(aes_encrypt('test','foobarfoobarfoobarfoobar')) as encrypted,
cast(aes_decrypt(unbase64(base64(aes_encrypt('test','foobarfoobarfoobarfoobar'))), 'foobarfoobarfoobarfoobar') as string) as decrypted;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论