使用LINQ加密列数据 [英] Encrypt column data with LINQ

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

问题描述

我不知道是否有容易解决这个还是我坚持与以下内容:

I was wondering if there is easy solution to this or I'm stuck with following:

在更新的数据库:


dti.Pass = Crypter.Encrypt(dti.Pass);
_db.SubmitChanges();

从数据库中选择当:

When selecting from DB:


Data.DbTableItem dti = _db.Single(a=>a.Id == id);
dti.Pass = Crypter.Decrypt(dti.Pass);

意义 - 我不是真的到写重复code和这似乎是由LINQ支持顺理成章的事情;所以我想,如果它是。

Meaning - I am not really into writing repetitive code and this seems like logical thing to be supported by LINQ; so I'm wondering if it is.

推荐答案

您可以添加一个局部类与属性封装这个逻辑,如:

You could add a partial class with a property encapsulating this logic like:

public partial class DbTableItem
{
  public String UnencryptedPass
  {
    get
    {
       return  Crypter.Decrypt(this.Pass);
    }

    set
    {
       this.Pass = Crypter.Encrypt(value)
    }
  }
}

希望它能帮助:)

Hope it helps : )

这篇关于使用LINQ加密列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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