c# - Getter/setter for two way encrypted property in a model -
i have need encrypt fields in database, so, need encrypt data going database, , decrypt when displaying it. i've got encryption methods , decryption methods set , had working in, example, action:
model.encryptedproperty = encrypt(viewmodel.property); viewmodel.property = decrypt(encryptedproperty);
that's fine, problem other developers need remember encrypt/decrypt property time use property. can problem new on project requires them know property being encrypted before hand. sought improve encryption encrypting/decrypting on model so:
private string _property; public string property { { return decryptstring(_property); } set { _property = encryptstring(value); } }
however, doesn't seem work, when view property in view, looks if though has encrypted encrypted data in database (i have tested using decryptstring(decriptstring(_property))
returns true value.
what solution here? there more elegant way approach this?
in scenario, might like:
[whateveryourdatalayerneeds("property")] public string encryptedproperty {get;set;} public string decryptedproperty { { return decryptstring(encryptedproperty); } set { encryptedproperty = encryptstring(value); } }
then database layer only talks first, , there no confusion.
Comments
Post a Comment