从 mysql 数据库加载时解密数据
Decrypt data when loaded from mysql database
这让我抓狂!
我有一个小程序从 mysql 数据库获取数据。
table tbl_credent 中有两列包含加密数据,称为 U_Password 和 U_SecQu.
我希望数据在加载到我的数据集中时被解密。
这是按原样加载数据的函数:
private void setBindSource()
{
string cmdString = "SELECT * FROM myDatabase.tbl_credent;";
MySqlDataAdapter da = new MySqlDataAdapter(cmdString, _connection);
//_connection is globally defined
ds = new System.Data.DataSet();
da.Fill(ds);
_BindSource = new System.Windows.Forms.BindingSource();
_BindSource.DataSource = ds.Tables[0];
}
我有解密数据的函数:
public string decryptData(string encryptedData, string password)
这工作正常,但我现在不知道如何将它与上面的功能一起使用。
你必须一个一个地解密每个字符串:
将此代码放在 da.Fill(ds);
之后
foreach (DataRow row in ds.Tables[0].Rows)
{
row["U_Password"] = decryptData(row["U_Password"] as string, "password");
row["U_SecQu"] = decryptData(row["U_SecQu"] as string, "password");
}
这让我抓狂!
我有一个小程序从 mysql 数据库获取数据。 table tbl_credent 中有两列包含加密数据,称为 U_Password 和 U_SecQu.
我希望数据在加载到我的数据集中时被解密。
这是按原样加载数据的函数:
private void setBindSource()
{
string cmdString = "SELECT * FROM myDatabase.tbl_credent;";
MySqlDataAdapter da = new MySqlDataAdapter(cmdString, _connection);
//_connection is globally defined
ds = new System.Data.DataSet();
da.Fill(ds);
_BindSource = new System.Windows.Forms.BindingSource();
_BindSource.DataSource = ds.Tables[0];
}
我有解密数据的函数:
public string decryptData(string encryptedData, string password)
这工作正常,但我现在不知道如何将它与上面的功能一起使用。
你必须一个一个地解密每个字符串:
将此代码放在 da.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
row["U_Password"] = decryptData(row["U_Password"] as string, "password");
row["U_SecQu"] = decryptData(row["U_SecQu"] as string, "password");
}