近期测试了一下postgresql的加密扩展插件pgcrypto的aes加密

安装加密扩展插件:pgcrypto

在主节点上安装

create extension pgcrypto;

postgresql通过配置文件加密(postgresql的加密扩展插件pgcrypto)(1)

aes加解密函数简单介绍

encrypt(data bytea, key bytea, type text) --加密

decrypt(data bytea, key bytea, type text) --解密

data 是需要加密的数据;type 用于指定加密方法

ASE方式加密:

select encrypt('postgres','abc','aes');

解密:

select convert_from(decrypt('\xd664687424b2806001d0744177284420','abc','aes'),'SQL_ASCII');

postgresql通过配置文件加密(postgresql的加密扩展插件pgcrypto)(2)

建表测试一下

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)

postgresql通过配置文件加密(postgresql的加密扩展插件pgcrypto)(3)

解密后可以看出加密前的密码

test=# select convert_from(decrypt(decode(password,'hex'),'abc','aes'),'SQL_ASCII') as real_pw,* from user_test;

real_pw | username | password

--------- ---------- ----------------------------------

123 | miya | a4bf9afce727dbd2805393a86a24096c

456 | kimi | 84279efc7942ca7364abcce78db90b0b

postgresql通过配置文件加密(postgresql的加密扩展插件pgcrypto)(4)

————————————————

版权声明:本文为CSDN博主「奈何流年」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/silenceray/article/details/110481225

,