postgresql 数据库列加密 postgres

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34658560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:07:36  来源:igfitidea点击:

Database column encryption postgres

databasepostgresqlencryptionaespgcrypto

提问by Nitin

How to encrypt column in postgres database using pgcrypto addon ?

如何使用 pgcrypto 插件加密 postgres 数据库中的列?

I am using postgres 9.3 and i need to encrypt one of my column , does postgres also support Aes encryption or by any mean i can achieve it ?

我正在使用 postgres 9.3 并且我需要加密我的一个专栏,postgres 是否也支持 Aes 加密或者我可以通过任何方式实现它?

采纳答案by Dmitry Savinkov

Yes, Postgres pgcryptomodule does support AES. All details with examples can be found here. As for the sample usage:

是的,Postgrespgcrypto模块确实支持AES. 可以在此处找到所有带有示例的详细信息。至于示例用法:

-- add extension
CREATE EXTENSION pgcrypto;

-- sample DDL
CREATE TABLE test_encrypt(
  value TEXT
);
INSERT INTO test_encrypt VALUES ('testvalue');

-- encrypt value
WITH encrypted_data AS (
  SELECT crypt('PasswordToEncrypt0',gen_salt('md5')) as hashed_value
)
UPDATE test_encrypt SET value = (SELECT hashed_value FROM encrypted_data);

Validate password:

验证密码:

SELECT (value = crypt('PasswordToEncrypt0', value)) AS match FROM test_encrypt;

Returns:

返回:

 match 
-------
 t
(1 row)