postgresql数据加密函数使用

可以采用md5函数进行数据加密存储和校验
<pre>
create table usertable(id serial,PASSWORD text);

insert into usertable (PASSWORD) values(md5('222222'));
insert into usertable (PASSWORD) values(md5('111111'));

SELECT * from usertable where PASSWORD=md5('222222')
</pre>
更加安全的是采用加盐模式,密码相同但是结果不同
<pre>
insert into usertable(password) values (crypt('123456',gen_salt('md5')));
insert into usertable(password) values (crypt('123456',gen_salt('md5')));
SELECT * from usertable where PASSWORD=crypt('123456',password);

2 $1$LEt6lBlJ$cSucnCctkaLU2tXCLCpLk0
3 $1$tP/w8ICv$Ucx9BP9j/eWmuAtiJjbTP/
</pre>

附:函数
**crypt()
crypt(password text, salt text) returns text
Calculates a crypt(3)-style hash of password. When storing a new password, you need to use gen_salt() to generate a new salt value. To check a password, pass the stored hash value as salt, and test whether the result matches the stored value.

crypt() 函数支持的加密算法**


PostgreSQL: 使用 pgcrypto 给敏感数据加密 - francs - My DBA LIFE

**gen_salt()
gen_salt(type text [, iter_count integer ]) returns text
Generates a new random salt string for use in crypt(). The salt string also tells crypt() which algorithm to use.The type parameter specifies the hashing algorithm. The accepted types are: des, xdes, md5 and bf.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 大自然a阅读 2,507评论 0 0
  • 亲爱的某先生, 这是写给你的第三封情书。 我对3这个数字心有余悸,我有过的恋爱,分别坚持9个月和3个月,记得室友说...
    许小慢慢阅读 3,744评论 0 4

友情链接更多精彩内容