我需要使用AES-256密钥加密一些列,我已经检查了pgcrypto的官方文档。但他们的例子让我抓狂。
例如,我有这样的数据库。
id first_name last_name is_active
0 John last_name 1 True
1 David last_name 2 False
2 Vincent last_name 3 True
3 Dean last_name 5 False我尝试过这样的东西:
UPDATE my_table SET first_name = ENCRYPT(user_name, 'my_encryption_key')我需要加密first_name和last_name列。我该如何实现它??
谢谢,qwew
发布于 2020-09-22 22:16:29
将pgp_sym_XXX()函数与armor()或encode()一起使用可获得base-64:
update my_table
set first_name = armor(
pgp_sym_encrypt(first_name, 'your_key', 'cipher-algo=aes256')
),
last_name = armor(
pgp_sym_encrypt(last_name, 'your_key', 'cipher-algo=aes256')
);AES-256很慢,因此可能需要很长时间才能针对整个表运行。
解密:
select pgp_sym_decrypt(dearmor(last_name), 'your_key', 'cipher-algo=aes256')
from my_table;https://stackoverflow.com/questions/64011268
复制相似问题