轨:存储在数据库中的加密数据 [英] Rails: storing encrypted data in database

查看:138
本文介绍了轨:存储在数据库中的加密数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的,因为机密数据被存储加密的数据库。我使用MongoDB的具有mongoid。有可能为这种数据库?你可以建议更换什么样的选择,如果它不是?

I want to encrypt database because confidential data is being stored. I use mongodb with mongoid. It possible for this kind of database? And what alternatives can you recomend, if it is not?

P.S。主要目的是:如果有人入侵服务器,盗取数据库,这将是unencryptable

P.S. Main purpose is: if anybody hack the server and steal DB, it would be unencryptable.

更新:感谢 nickh ,我发现很多的soultions的ActiveRecord的,但没有对Mongoid等蒙戈clinets。这将是巨大的,找到一些soultion为蒙戈和Mongoid!

UPDATE: thanks for nickh, I found very many soultions for ActiveRecord, but nothing for Mongoid and other Mongo clinets. It would be great to find some soultion for Mongo and Mongoid!

推荐答案

我一般都是attr​​_encrypted与蒙戈和Mongoid工作。它只需几调整。

I have gotten attr_encrypted working with Mongo and Mongoid. It takes only a few tweaks.

请确保所有由attr_encrypted自动创建encrypted_字段在模型中显式创建。举例来说,如果你有:

Make sure that all of the encrypted_ fields that are automatically created by attr_encrypted are explicitly created in the model. For instance, if you have:

    attr_encrypted :email, :key => 'blah blah blah', :encode => true

您需要有:

    field :email, :type => String
    field :encrypted_email, :type => String

此外请注意你需要告诉它连接code中的加密字符串,否则蒙戈会大声抱怨。

Also notice you need to tell it to encode the encrypted string otherwise Mongo will complain loudly.

最后,如果你加密哈希,做到这一点:

Lastly, if you're encrypting a hash, do this:

    field :raw_auth_hash, :type => Hash
    field :encrypted_raw_auth_hash, :type => String

    attr_encrypted :raw_auth_hash, :key => 'blah', :marshal => true, :encode => true

这篇关于轨:存储在数据库中的加密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆