postgres加密解密pgcrypto

 
create extension pgcrypto;

定义--encrypt(bytea, bytea, text)--

text加密方式

AES
DES/3DES/CAST5
Blowfish

查询表时一定符合类型

select nm, encrypt(cast(tb1.nm as bytea) ,'aa','aes') from tb1

select nm,test,
encrypt(cast(test as bytea) ,'aa','aes') as 加密, 
convert_from(decrypt(encrypt(cast(test as bytea),'aa','aes'),'aa','aes'),'SQL_ASCII') as 解密
from tb1

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

select encrypt('123456年a','aa','aes');
--\000\003AXv\327\370\351\363\006\242\267A\245yX
 select convert_from(decrypt('\000\003AXv\327\370\351\363\006\242\267A\245yX','aa','aes'),'SQL_ASCII');
--123456年a 
select convert_from(decrypt(encrypt('123456年a','aa','aes'),'aa','aes'),'SQL_ASCII');
--123456年a 

猜你喜欢

转载自blog.csdn.net/ozhy111/article/details/81939226