问题描述
我想加密数据库,因为正在存储机密数据.我将 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. Main purpose is: if anybody hack the server and steal DB, it would be unencryptable.
更新:感谢 nickh,我发现了很多 ActiveRecord 的灵魂,但对于 Mongoid 和其他 Mongo clinets 没有.为 Mongo 和 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 与 Mongo 和 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
另请注意,您需要告诉它对加密字符串进行编码,否则 Mongo 会大声抱怨.
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
这篇关于Rails:在数据库中存储加密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!