I just need some advise here. I need to protected some column data, so I have been googling about encryption in C# 4.0/Sql server 2008 (not R2).
This is probably what I need:
"When the data must be protected from sysadmins. Practically, in this scenario it would be best not to use SQL Server internal encryption and far better to rely exclusively on the middle tier to perform encryption and decryption. It would be very difficult to protect your data from a determined sysadmin if your keys are stored in SQL Server." Source: msdn
What is the correct approach?
I have tried to save data which was encrypted with Rijndael and to database.
I get error: Length of the data to decrypt is invalid
I haven't googled this yet.
Should I continue struggeling with this or should I try to solve this with CLR or what? I just can't find a tutorial which shows me how to encrypt/decrypt in business layer.
Any suggestions?
Thank you
EDIT:
Ok this is what I have so far. The data is encrypted with Rinjdael as shown before. It is stored in column
TestCrypt (varbinary(255), null)
I looks like this in the database:
0xF6CA99F5B6BFA1D9A0BD2381177E049E02F381078966195B68A54A5BEC4C
It is retrieved with a sp, such as:
SELECT cast(s.TestCrypt AS varbinary) AS TestCrypt
And in data access layer:
while (reader.Read())
{
data.TestCrypt = (byte[])reader["TestCrypt"];
}
The error is found in DecryptStringFromBytes at this row
plaintext = srDecrypt.ReadToEnd();
The error: Length of the data to decrypt is invalid.