Search code examples
c#xsdstrongly-typed-dataset

Strong Type Data Set : Override column get : set


we are using data sets as our data access layer. currently there are some columns that store encrypted data.

using CLR i was able to create an SQL function for decryption of the data in a select but in discussion we have determined that to be a security risk.

what i am looking to do is to either

  1. override the get/set of the data table column so that when on the get it will un encrypt the value and return a readable string and on the set will encrypt the data.
  2. or do something with the table adapter so that on the select / update would do the same as above.

Solution

  • You may try to create an extension methods for this task:

    namespace ExtensionMethods
    {
        public static class MyExtensions
        {
            public static void SetEncryptColumn(this DataSetType.DataTableRow row, string value)
            {
                row.Encrypt = EncryptValue(value);
            }
    
            public static string GetEncryptColumn(this DataSetType.DataTableRow row)
            {
                return DecryptValue(row.Encrypt);
            }
        }   
    }
    

    http://msdn.microsoft.com/en-us/library/bb383977%28v=vs.90%29.aspx