我想使用 aes 256 加密技术对我的 postgreSQL 数据库中的 area_code 列进行加密。 这是发生的事情。我能够轻松地对其进行加密,但我无法对其进行解密。
这是运行良好的加密查询:
update mytable t1 set area_code = t2.area_code from (select pgp_sym_encrypt(area_code,'Password', 'compress-algo=1, cipher-algo=aes256') as area_code,area_name from mytable) t2 where t1.area_name = t2.area_name;
但是,如果我给出类似的东西,解密查询似乎不起作用
update mytable t1 set area_code = t2.area_code from (select pgp_sym_decrypt(area_code,'Password') as area_code,area_name from mytable) t2 where t1.area_name = t2.area_name;
甚至当我尝试查看解密的 area_code 时
select pgp_sym_decrypt((select area_code from ci), 'Password') ;
唯一可行的是当我使用单个记录并直接输入加密文本时。
select pgp_sym_decrypt('aes.encrypted.string.given.as.input', 'Password') ;
最佳答案
您应该将加密数据存储到 bytea 列中,而不是文本列中。您可以将其从文本转换为 bytea:
pgp_sym_decrypt(area_code::bytea,'Password')
为什么不直接更新表,而是在更新时进行退化的自连接?
关于sql - pgp_sym_encrypt 和解密 postgresql 中的整个列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26656910/