locked
Encryption & Decryption RRS feed

  • Question

  • Dear Experts, 

    I have data table that contains sensitive information and before loading to the DB. I need to encrypt certain those columns. We have a powershell version which does something like below. Do we have something similar for C#.

           IF(
    			   ($sql_text -match ("[a-zA-Z0-9_\\.]+@[a-zA-Z0-9\\.]+")) {
                  
     
                   
                    $someString_sql_text = "$sql_text"
                    $sql_text = $someString_sql_text   | ConvertTo-SecureString -AsPlainText -Force  | ConvertFrom-SecureString -Key $key 
                                    
                    }

    The match part I think simply get replaced with contains for C#.

    Please assist.

    Sunday, April 5, 2020 3:59 AM

All replies

  • Hello,

    You would have to roll your own solution but...

    Consider instead, for instance with SQL-Server "always encrypted" coupled with using parameters for your queries provides good encryption. See also Encrypt a Column of Data.

    Also if your apps ever move off the Windows platform SecureString is foreign on other platforms, they have their own methods to perform similar operations. .NET Core does not implement SecureString.

    Couple this with other methods such as authentication measures and using parameterized queries this is a better way to go then encrypting as done now.

    In closing, I only mentioned SQL-Server simply as it's the predominant database used here and you didn't indicate the database being used.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, April 5, 2020 9:15 AM
  • Hello,

    You would have to roll your own solution but...

    Consider instead, for instance with SQL-Server "always encrypted" coupled with using parameters for your queries provides good encryption. See also Encrypt a Column of Data.

    Also if your apps ever move off the Windows platform SecureString is foreign on other platforms, they have their own methods to perform similar operations. .NET Core does not implement SecureString.

    Couple this with other methods such as authentication measures and using parameterized queries this is a better way to go then encrypting as done now.

    In closing, I only mentioned SQL-Server simply as it's the predominant database used here and you didn't indicate the database being used.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thank you Ma'am,

    Am focusing on 2 data stores

    1. Elastic Search : I guess same level support of encryption support isn't available.

    2. SQL Server : I can use column level data encryption.

    Yes, am looking forward to a solution that works on both .net core & framework. But I guess currently I don't have much of an alternate to secure strings.

    Thanks

    Priya

    Sunday, April 5, 2020 9:48 AM
  • Here is Microsoft's recommendation for .NET Core 

    https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, April 5, 2020 10:06 AM
  • You know that there is a .Net cryptography namespace. It seems to me there is in that a lot to choose from.

    https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography?view=netframework-4.8


    Success
    Cor

    Sunday, April 5, 2020 12:45 PM