I have a column with encrypted name(all other columns are not encrypted) in SQL Database table. And I have to decrypt the column with encrypted name to show in DataGrid to users of my application but the actual table of SQL database should not be changed.(has to remain as encrypted name).
I think UpdateCommand works to update the actual table and I have to find an alternative than below UpdateCommand.
Or is there alternative way to decrypt only 1 column on DataTable which is not influencing the actual table of database?
My simple code is,
SqlCommand gridcomm = new SqlCommand();
gridcomm.Connection = Conn;
gridcomm.CommandText = "SELECT Id, customername, phonenumber FROM customers";
SqlDataAdapter gridda = new SqlDataAdapter(gridcomm);
SqlDataReader gridreader = gridcomm.ExecuteReader();
while (gridreader.Read())
{
}
gridreader.Close();
DataTable griddt = new DataTable("customers");
gridda.Fill(griddt);
foreach (DataRow row in griddt.Rows)
{
string strcustomername = (string) row["customername"].ToString();
bytecustomername = Convert.FromBase64String(strcustomername);
string decryptedcustomername = DecryptStringFromBytes_Aes(bytecustomername, byteAESKey, byteAESIV);
row["customername"] = decryptedcustomername;
}
gridda.UpdateCommand = new SqlCommandBuilder(gridda).GetUpdateCommand();
dataGrid_Totalcustomerlist.ItemsSource = griddt.DefaultView;
gridda.Update(griddt);