postgresql 中的加密扩展插件pgcrypto用法分析

近期测试了一下postgresql的加密扩展插件pgcrypto的aes加密
 
安装加密扩展插件:pgcrypto
 
在主节点上安装
 
1create extension pgcrypto;
 
 
aes加解密函数简单介绍
 
encrypt(data bytea, key bytea, type text) –加密
decrypt(data bytea, key bytea, type text) –解密
 
data 是需要加密的数据;type 用于指定加密方法
 
ASE方式加密:
 
1select encrypt('postgres','abc','aes');
 
解密:
 
1select convert_from(decrypt('\xd664687424b2806001d0744177284420','abc','aes'),'SQL_ASCII');
 
 
建表测试一下
 
test=# create table user_test(username varchar(20),password varchar(60));
CREATE TABLE
test=# insert into user_test values('miya',encode(encrypt('123','abc','aes'),'hex'));
INSERT 0 1
test=# insert into user_test values('kimi',encode(encrypt('456','abc','aes'),'hex'));
INSERT 0 1
test=# select * from user_test;
 username |    password   
———-+———————————-
 miya  | a4bf9afce727dbd2805393a86a24096c
 kimi  | 84279efc7942ca7364abcce78db90b0b
(2 rows)
【声明】:芜湖站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

相关文章