Azhar Rahi

Azhar Rahi

  • NA
  • 191
  • 0

Symmetric Key Encryption in SQl Server and decryption in C#

Jan 26 2018 10:27 AM
hope everyone will be fine here. I have created a column with encrypted data using SQL Server Symmetric Key encryption feature. What I have done is attached in a file:
 

It has successfully Updated EncryptedPhone column with encrypted data (which is in varbinary).

Now the problem is that, I am using LINQToSQL on application and I am using inline Linq To SQL query (not stored procedure or sql query), I need to decrypt this data to view on the page. As you can see from the above database code, I am using TripleDES to create encrypted data. However I am unable to understand how can I achieve the decrypted data on C# which was encrypted through SQL query.

 
Actually I have written a code, but it throws error: "length of the data to decrypt is invalid." What I have found from the articles that the block size of the string must be 128 bit, however the length of the varbinary as string getting from SQL query Server query is 74. I am not sure how to tackle with the length error. It is confusing for me. 

Answers (1)