简体   繁体   English

Postgres:像搜索在列级别加密数据的地方

[英]Postgres : Like search where data is encrypted at column level

I have a Postgresql db of version 9.4.1 to be very specific.我有一个 9.4.1 版的 Postgresql 数据库,非常具体。 Values of certain columns of some table are encrypted, now i have scenario where i need to use such encrypted columns in where condition with like pattern.某些表的某些列的值是加密的,现在我有一个场景,我需要在具有类似模式的 where 条件下使用此类加密列。 To encrypt data under columns i am used AES encryption scheme and doing encryption() and decryption() on java side only, so now my database is not aware of what plaintext values are stored.为了加密列下的数据,我使用了 AES 加密方案并仅在 Java 端进行了加密()和解密(),所以现在我的数据库不知道存储了哪些明文值。

Above logic works perfectly for exact search but LIKE search is failing here以上逻辑适用于精确搜索,但 LIKE 搜索在这里失败

For example: Let's say data under customername column of customer table is encrypted and i want to perform like search on customername as follows.例如:假设客户表的 customername 列下的数据已加密,我想对 customername 执行如下搜索。

select customer_id from customer where customername like '%'+encryption(ABC)+'%'

Post evaluating multiple suggested options, i finally concluded issue using Pgcrypto module of postgres.在评估多个建议选项后,我最终使用 postgres 的 Pgcrypto 模块总结了问题。 pgcrypto allows like search too, only drawback here is length of column needs to increased. pgcrypto 也允许类似搜索,唯一的缺点是需要增加列的长度。

Details of Pgcrypto module are available here. Pgcrypto 模块的详细信息可在此处获得。

https://www.postgresql.org/docs/9.0/pgcrypto.html https://www.postgresql.org/docs/9.0/pgcrypto.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM