Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
如何使用pgcrypto加密postgresql中的整数和日期时间数据类型_Sql_Postgresql - Fatal编程技术网

如何使用pgcrypto加密postgresql中的整数和日期时间数据类型

如何使用pgcrypto加密postgresql中的整数和日期时间数据类型,sql,postgresql,Sql,Postgresql,以下是我加密该列的代码: UPDATE users SET (userid, modifieddate) = ( PGP_SYM_ENCRYPT('0', 'AES_KEY'), PGP_SYM_ENCRYPT('2018-06-19 08:40:23', 'AES_KEY') ) WHERE id='3'; 但它的错误是: 列“userid”的类型为integer,但表达式的类型为byte 您的表列users.userid和users.modifieddate应为类型

以下是我加密该列的代码:

UPDATE users 
SET  (userid, modifieddate) = 
(
    PGP_SYM_ENCRYPT('0', 'AES_KEY'),
    PGP_SYM_ENCRYPT('2018-06-19 08:40:23', 'AES_KEY')
) 
WHERE id='3';
但它的错误是:

列“userid”的类型为integer,但表达式的类型为byte


您的表列
users.userid
users.modifieddate
应为类型
BYTEA
,因为
pgcrypto
模块使用
BYTEA
类型生成加密结果。

您不能只加密一个用户的id,而将其其余部分原封不动放置,如果您想实现这一点,您需要修改@C.C.Hsu提到的表,即将用户ID的数据类型转换为bytea或文本,该文本能够存储加密数据和正常数据

alter table users alter column userid type bytea using PGP_SYM_ENCRYPT(userid::text, 'AES_KEY');
alter table users alter column modifieddate type bytea using PGP_SYM_ENCRYPT(modifieddate::text, 'AES_KEY');

我无法更改我的表数据types@adams我面临着一个类似的问题,您是否找到了一种解决方案,可以对数字数据进行加密,并保存数据类型?