Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用pgcrypto加密整个列_Sql_Postgresql_Encryption_Pgcrypto - Fatal编程技术网

Sql 使用pgcrypto加密整个列

Sql 使用pgcrypto加密整个列,sql,postgresql,encryption,pgcrypto,Sql,Postgresql,Encryption,Pgcrypto,我需要使用AES-256密钥加密一些列,我已经查看了pgcrypto的官方文档。但是他们的例子让我很生气 例如,我有这样的数据库 id first_name last_name is_active 0 John last_name 1 True 1 David last_name 2 False 2 Vince

我需要使用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

使用
pgp\u sym\u 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;