Encrypting a field value in a Linq-to-Sql object

I need to encrypt some fields in my Linq2Sql Entity. I would also like the encryption and decryption process to be transparent to the consumer of the object, which means that after the object is loaded into memory, the field appears as a string of regular values ​​(decrypted), but the same fields get encrypted when they are Databases are saved.

+3
source share
2 answers

There is another option: you can "hide" the actual property, for example. protectedand add the "fake" property publicto the partial entity class that will encrypt / decrypt this internalin getter / setter, so it will be transparent to the user:

.dbml file:

<Column Name="Password" 
    Member="PasswordInternal" 
    AccessModifier="Protected" 
    Type="System.String" 
    DbType="Varchar(64) NOT NULL" 
    CanBeNull="false" />

and then in a partial class:

public partial class YourEntity
{
   public string Password
   {
        get
        {
            return Crypter.Decrypt(this.PasswordInternal)
        }
        set
        {
            this.PasswordInternal = Crypter.Encrypt(value)
        }
   }
}
+2
source

well, SQL 2008 can encrypt a table column, and the application should not handle this. heres the link . say it has a run cost on sql server cpu.

+2
source

Source: https://habr.com/ru/post/1794463/


All Articles