簡體   English   中英

加密datagridview值C#

[英]Encrypting datagridview values C#

我正在使用winforms應用程序,該應用程序允許用戶在datagridview中填寫帳戶和密碼信息,數據源是一個數據表,它將使用.net mysql連接器連接到mysql服務器。

當用戶保存數據表時,需要將數據加密到mysql數據庫中,因此,如果有人侵入mysql服務器,則數據將無用。

為了進行加密和解密,我使用了一個名為SimpleAES的類( C#的簡單不安全雙向“混淆”

這對於文本框等非常有用,但是如何通過數據網格視圖循環以加密用戶提供的所有值?

我嘗試了以下方法。

    private void encryptAccounts()
        {
            SimpleAES simpleAES1 = new SimpleAES();

            string password;
password= dataGridViewAccounts[4,0].Value.ToString();

            dataGridViewAccounts[4,0].Value = simpleAES1.EncryptToString(password);
        }

這只會加密第一行的密碼,如何為每一行創建一個循環

我如何為每一行創建一個循環

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);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM