我正在尝试在插入 MongoDB 之前和之后加密和解密值。我正在使用猫鼬模式并调用 get 和 set 方法进行加密和解密。通过调用 set 方法对数据进行加密,但是在从 MongoDB 检索数据时它没有解密。这是我的架构和加密解密方法:
var tempSchema = new Schema({
_id: {type: Schema.ObjectId, auto: true},
name:{type: String},
sample_details:{
_id: false,
objects: [{
object_key:{type: String},
object_value:{type: String, get:decrypt, set:encrypt}
}],
type_params:[{
type_key:{type: String},
type_value:{type: String, get:decrypt, set:encrypt}
}],
test_body:{type: String, get:decrypt, set:encrypt}
}}, {
toObject : {getters: true, setters: true},
toJSON : {getters: true, setters: true}
});
Run Code Online (Sandbox Code Playgroud)
以下是使用的加密和解密方法:
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc', secret_key);
var crypted = cipher.update(text,'utf8','hex');
crypted += cipher.final('hex');
return crypted;
} …Run Code Online (Sandbox Code Playgroud) 我正在处理的应用程序正在使用旧版本的 com.lowagie itext 2.x,现在我想将其移动到更高版本到 4.x,但看起来有几个包正在被重命名/删除等。我会想问一下有没有人迁移到4.x?如果是这样,任何建议都会很棒。提前致谢