我想用C#创建一个ASP.Net应用程序,我将在SQL Server 2005上存储数据,这些数据将被加密我想找到一个算法用C#加密数据并在SQL服务端解密它我想要使用SQL加密某些数据并使用C#解密它的最佳算法是什么?
private byte[] key = {
0x61,
0x72,
0x84,
0x7a,
0x24,
0x43,
0x65,
0x64,
0x73,
0x55,
0x64,
0x75,
0x66
};
const string PASSWORD = "TestPassword";
public object Encrypt(string sPlainText)
{
byte[] aPlainBytes = null;
PasswordDeriveBytes aPassword = default(PasswordDeriveBytes);
aPlainBytes = System.Text.Encoding.Unicode.GetBytes(sPlainText);
aPassword = new PasswordDeriveBytes(PASSWORD, key);
byte[] sEncryptedData = Encrypt(aPlainBytes, aPassword.GetBytes(32), aPassword.GetBytes(16));
//' MessageBox.Show(Convert.ToString(sEncryptedData.ToString))
return Convert.ToBase64String(sEncryptedData);
}
private byte[] Encrypt(byte[] sPlainData, byte[] aKey, byte[] aIV)
{
MemoryStream oMemoryStream = new MemoryStream();
Rijndael oRijndael = Rijndael.Create();
oRijndael.Key = aKey; …Run Code Online (Sandbox Code Playgroud)