加密 datagridview 值 C#
Encrypting datagridview values C#
我正在开发一个 winforms 应用程序,它允许用户在 datagridview 中填写帐户和密码信息,数据源是一个数据表,它将使用 .net [=] 连接到 mysql 服务器24=]连接器。
当用户保存数据表时,数据需要加密到mysql数据库,所以万一有人侵入mysql服务器,数据就没用了。
为了加密和解密,我使用了一个名为 SimpleAES (Simple insecure two-way "obfuscation" for C#)
的 class
这对文本框等非常有用,但我如何循环遍历 datagridview 来加密用户提供的所有值?
我尝试了以下方法。
private void encryptAccounts()
{
SimpleAES simpleAES1 = new SimpleAES();
string password;
password= dataGridViewAccounts[4,0].Value.ToString();
dataGridViewAccounts[4,0].Value = simpleAES1.EncryptToString(password);
}
这只会加密第一行的密码,如何为每一行创建一个循环
how can I create a loop for every row
private void encryptAccounts()
{
SimpleAES simpleAES1 = new SimpleAES();
// iterate over all DGV rows
for (int r = 0; r < dataGridViewAccounts.Rows.Count; r++)
{
if (dataGridViewAccounts[4, r].Value != null)
{
string password = dataGridViewAccounts[4, r].Value.ToString();
dataGridViewAccounts[4, r].Value = simpleAES1.EncryptToString(password);
}
}
// OR
foreach (DataGridViewRow row in dataGridViewAccounts.Rows)
{
if (row.Cells[4].Value != null)
{
string password = row.Cells[4].Value.ToString();
row.Cells[4].Value = simpleAES1.EncryptToString(password);
}
}
}
我正在开发一个 winforms 应用程序,它允许用户在 datagridview 中填写帐户和密码信息,数据源是一个数据表,它将使用 .net [=] 连接到 mysql 服务器24=]连接器。
当用户保存数据表时,数据需要加密到mysql数据库,所以万一有人侵入mysql服务器,数据就没用了。
为了加密和解密,我使用了一个名为 SimpleAES (Simple insecure two-way "obfuscation" for C#)
的 class这对文本框等非常有用,但我如何循环遍历 datagridview 来加密用户提供的所有值?
我尝试了以下方法。
private void encryptAccounts()
{
SimpleAES simpleAES1 = new SimpleAES();
string password;
password= dataGridViewAccounts[4,0].Value.ToString();
dataGridViewAccounts[4,0].Value = simpleAES1.EncryptToString(password);
}
这只会加密第一行的密码,如何为每一行创建一个循环
how can I create a loop for every row
private void encryptAccounts()
{
SimpleAES simpleAES1 = new SimpleAES();
// iterate over all DGV rows
for (int r = 0; r < dataGridViewAccounts.Rows.Count; r++)
{
if (dataGridViewAccounts[4, r].Value != null)
{
string password = dataGridViewAccounts[4, r].Value.ToString();
dataGridViewAccounts[4, r].Value = simpleAES1.EncryptToString(password);
}
}
// OR
foreach (DataGridViewRow row in dataGridViewAccounts.Rows)
{
if (row.Cells[4].Value != null)
{
string password = row.Cells[4].Value.ToString();
row.Cells[4].Value = simpleAES1.EncryptToString(password);
}
}
}