score:6

Accepted answer

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 : )

score:4

you could define a fake password property which encapsulates your password logic and an original password field (which is mapped to the database - passwordinternal in my example) should be e.g. internal.

public partial class yourentity
{
   public string password
   {
        get
        {
            return crypter.decrypt(this.passwordinternal)
        }
        set
        {
            this.passwordinternal = crypter.encrypt(value)
        }
   }
}

afaik, there is no built-in functionality you're looking for.

score:4

you should use sql server cryptographic functions, encryptbykey and decryptbykey. even better still, use transparent database encryption. right now you encrypt and decrypt the password with some key stored who know where. databases have this nasty habit of moving around and being restored on completely new machines in case of disaster recovery or as part of various high availability scenarios, and you'll discover that storing the encrypted data in the database and the encryption key in the system key store (or worse, in the app) has left you with a bunch of 'completely secure' data, impossible to decrypt because you lost the key.


Related Query