MongoDB 数据加密
Posted _雪辉_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MongoDB 数据加密相关的知识,希望对你有一定的参考价值。
xuehui:PRIMARY> db.xuehui.insertOne({"name":"xuehui","password":"970125"});
{
"acknowledged" : true,
"insertedId" : ObjectId("60a5fbb4a16fd1c94ac0024b")
}
xuehui:PRIMARY> db.xuehui.insertOne({"name":"zijie","password":"970125"});
{
"acknowledged" : true,
"insertedId" : ObjectId("60a5fbb4a16fd1c94ac0024c")
}
xuehui:PRIMARY> db.xuehui.find()
{ "_id" : ObjectId("60a5fbb4a16fd1c94ac0024b"), "name" : "xuehui", "password" : "970125" }
{ "_id" : ObjectId("60a5fbb4a16fd1c94ac0024c"), "name" : "zijie", "password" : "970125" }
加密数据
xuehui:PRIMARY> db.xuehui.find().forEach( function(documentPass){
... documentPass.passwordencryption = hex_md5(documentPass.password);
... db.xuehui.save(documentPass);
... documentPass.nameencryption = hex_md5(documentPass.name);
... db.xuehui.save(documentPass);
... });
xuehui:PRIMARY> db.xuehui.find()
{ "_id" : ObjectId("60a5fbb4a16fd1c94ac0024b"), "name" : "xuehui", "password" : "970125", "passwordencryption" : "1e358a65a75ddd68e8d082a4055a63a8", "nameencryption" : "49224120e8a4b47f00c00c1be1c07feb" }
{ "_id" : ObjectId("60a5fbb4a16fd1c94ac0024c"), "name" : "zijie", "password" : "970125", "passwordencryption" : "1e358a65a75ddd68e8d082a4055a63a8", "nameencryption" : "959683541aace5d1bd0004f422938380" }
以上是关于MongoDB 数据加密的主要内容,如果未能解决你的问题,请参考以下文章
Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段