如何在 visual studio 2010 c# 中加密数据库列

How to encrypt a database coloumn in visual studio 2010 c#

大家好,我在 visual studio 2010 年使用 c# 语言创建了一个连接到我网站的 oracle 数据库。我有一个 table,其中用户密码保存在 table 中。

当我在table中输入密码时可以看到(我不想要)。我希望它被加密以确保一旦输入数据库就无法看到密码。任何帮助将不胜感激。 我的用户 table 看起来像这样:

Create TABLE users (
  user_id number(5) NOT NULL , 
  user_username VARCHAR(30), 
  user_password VARCHAR(20), 
  user_email VARCHAR(75), 
  user_street VARCHAR(50), 
  user_city VARCHAR(50), 
  user_state VARCHAR(2), 
  user_postcode VARCHAR(20), 
  user_phone VARCHAR(50),  
  PRIMARY KEY (user_id) 
) ;

谢谢

你可以使用散列技术,

public class 安全 { public static string HashSHA1(字符串值) { var sha1 = System.Security.Cryptography.SHA1.Create(); var inputBytes = Encoding.ASCII.GetBytes(值); var hash = sha1.ComputeHash(inputBytes);

    var sb = new StringBuilder();
    for (var i = 0; i < hash.Length; i++)
    {
        sb.Append(hash[i].ToString("X2"));
    }
    return sb.ToString();
}

}

在 visual studio 中, cmd.Parameters.AddWithValue("@password", 密码);

cmd.Parameters.AddWithValue("@password", Security.HashSHA1(密码));

// 将被存储为,

用户 ID |用户名 |密码

1 |冲积物 |我的秘密密码

2 |冲积物 | F032680299B077AFB95093DE4082F625502B8251

存储密码的最佳和常用方法是,存储密码散列 如下所示:-

HASHBYTES('SHA1', convert(VARCHAR(20), @user_password)

通过添加hash可以检查密码是否匹配

注意:- 这里您可能还不知道存储在数据库列中的实际密码是什么。因此,即使黑客破解了您的完整数据库,他仍然无法知道密码。

另外,你可以在网上搜索一些更安全和加密的安全相关的东西。

这里还有一些链接:-

Querying encrypted values in the database

Best way to store password in the database

Encrpyt and Decrypt the username and password

希望以上内容对您有所帮助。