Pg extention pgcrypto

目录

文档用途

详细信息

文档用途

了解pgcrypto扩展

详细信息

1.介绍

pgcrypto扩展是pg内核中支持的扩展插件,全部编译后,会扩展目录中找到。 (GP/HGDW也可以安装pgcrypto扩展模块) pgcrypto提供了一组加密函数。可以实现服务器端的数据加密。我们可以在SQL语句中调用这些函数来完成数据的加密

pgcrypto可以加密存储数据,但是读取时无法透明解密数据。通常只用于加密存储已知的密码,不建议用于加密列数据

2.安装

1.查看组件脚本是否存在

ls -atl $PGHOME/share/postgresql/extension

2.安装扩展

postgres=# create extension pgcrypto;
CREATE EXTENSION

(老版本需要执行脚本安装 psql -d testdb -f $HOME/share/postgresql/contrib/pgcrypto.sql)

3.加密函数使用

加密函数digest

postgres=# select digest('jason', 'md5');
               digest               
------------------------------------
 \x2b877b4b825b48a9a0950dd5bd1f264d
(1 row)

加密函数encrypt

postgresql=# 
postgresql=# select encrypt('123456','aa','aes');
                   encrypt                   
---------------------------------------------
 9\303\306euz\017\371s\270?\271\214\303\326?
(1 row)

读取时需要解密
postgresql=# 
postgresql=# select convert_from(decrypt('\x39c3c665757a0ff973b83fb98cc3d63f','aa','aes'),'SQL_ASCII');
 convert_from 
--------------
 123456
(1 row)

postgresql=# 

更多详细信息请登录【瀚高技术支持平台查看】https://support.highgo.com/#/index/docContent/95a2a24d03fc1c07

猜你喜欢

转载自blog.csdn.net/pg_hgdb/article/details/105945581