简体   繁体   English

MongoDb 场加密

[英]MongoDb Field Encryption

I am trying to set up a system where I can have a collection of users with encrypted fields and do a search on those fields.我正在尝试建立一个系统,我可以在其中收集具有加密字段的用户并在这些字段上进行搜索。

I have tried looking on MongoDB documentation but there is no clear route我试过查看 MongoDB 文档,但没有明确的路线

I want to have something like this我想要这样的东西

{
    fname : John,
    lname : Smith,
    ssn : "555-55-5555"
}

look like this看起来像这样

{
    fname : John,
    lname : Smith,
    ssn : "fweiubv3b443hbv4f48h"
}

then be able to do a search like然后可以进行类似的搜索

db.users.find({ssn : "555-55-5555"})

The goal is to have a schema run and create the collection目标是运行模式并创建集合

db.createCollection("user", {
    "validator": {
       "$jsonSchema": {
           ....
});

A common strategy to solve this problem requires two fields on the model.解决此问题的常用策略需要 model 上的两个字段。 One is a hash, the other is the result of encryption.一个是hash,另一个是加密的结果。

Taking your SSN example:以您的 SSN 为例:

Storing存储

  • Take the plaintext SSN and HMAC it using key1 .使用key1获取明文 SSN 和 HMAC。
  • Take the plaintext SSN and encrypt it using a AAED mode like GCM with key2 .获取明文 SSN 并使用 AAED 模式(如GCMkey2 )对其进行加密。
  • Store the hash and encryption result in the database document or whatever.将 hash 和加密结果存储在数据库文档或其他文件中。 Names like ssn_hash and ssn_enc might be appropriate.ssn_hashssn_enc这样的名称可能是合适的。

Looking Up向上看

  • Take the SSN you are searching for and HMAC it using key1 .获取您正在搜索的 SSN 并使用key1对其进行 HMAC。
  • Perform a lookup on ssn_hash for the result above.ssn_hash上查找上述结果。

Getting Plaintext获取明文

  • Lookup the database document however.但是查找数据库文档。
  • Decrypt ssn_enc with key2 .使用key2解密ssn_enc

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

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