postgres加密解密pgcrypto

复制代码
create extension pgcrypto;

 --增加,加密解密模块;

drop extension pgcrypto;

--删除,加密解密模块;
复制代码
复制代码
定义--encrypt(bytea, bytea, text)--
update bill_his_yun set yun_ip=encode(encrypt('202.99','p08','des') ,'hex') where yun_id=299904910298845184;


    select decrypt(yun_ip,'p08','des')  from bill_his_yun  where yun_id=299904910298845184;
    
    
    select convert_from(decrypt(decode(yun_ip,'hex'),'p08','des'),'SQL_ASCII') as yun_ip from bill_his_yun where yun_id=299904910298845184;
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 
—————
复制代码

 

posted @   Thenext  阅读(562)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示