0

I apologize if this has been addressed before, but I have done some research and not been able to come up with a clear answer on my own.

I am using PHP's openSSL functions to encrypt data using 256 bit AES and storing it in an SQL database. I was surprised that (at least from my research), there did not seem to be an easy way to decrypt this data (there is in MySql after all).

Perhaps I am simply overlooking something incredibly obvious but how can I decrypt this data so that I can display it to trusted users? I can use either C# or Transact SQL to perform this task, but, to my surprise, have yet to figure how to accomplish it with either.

Again, I do not mean to waste anybody's time or just have someone 'feed' me the answers, but I have looked into without success. As such, I really appreciate any help.

KellyM
  • 2,472
  • 6
  • 46
  • 90
  • You say there is no easy way to decript it, do you mean in C# or what? – Scott Chamberlain Jun 21 '16 at 02:30
  • Check this site. http://www.c-sharpcorner.com/UploadFile/chinnasrihari/data-encryption-and-decryption-in-sql-server-2008/ – Sam Jun 21 '16 at 02:37
  • how do you encrypt the data? – zaph Jun 21 '16 at 02:49
  • The data is encrypted using AES256 through PHP's openSSL functions. Yes, decrypting by PHP would make sense, but it will not work for my purpose. I am struggling to find a way to do it in either C# or Transact SQL. Honestly, I would prefer to do it in C#, but could not find classes or methods that support AES256 (though again, I could be overlooking it). Thanks! – KellyM Jun 21 '16 at 23:51

2 Answers2

0

If you are using SQL Server you can load keys into the server to do it. Or you can write custom code in C# and load that in as a procedure.

Regardless the hard part is managing your key for encryption. The following page has a reasonable start on how it works in TSQL. MSDN Link

Spence
  • 28,526
  • 15
  • 68
  • 103
0

AES with a 256-bit key has a few implementation in C#. Just search SO for [C#] AES, one SO example, also MSDN AES.

Note that a lot of older implementations go by the name Rijndael which is a super set of AES. Be careful, Rijndael supports several block sizes so if you need AES select Rijndael a 128-bit block size and a 256-bit key (the key size is often selected automatically by the supplied key).

Community
  • 1
  • 1
zaph
  • 111,848
  • 21
  • 189
  • 228