【问题标题】:How to encrypt a database coloumn in visual studio 2010 c# [duplicate]如何在visual studio 2010 c#中加密数据库列[重复]
【发布时间】:2015-06-25 01:48:03
【问题描述】:

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

当我在表格中输入密码时,可以看到它(我不想要)。我希望它被加密以确保一旦输入数据库就看不到密码。任何帮助将不胜感激。 我的用户表如下所示:

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

谢谢

【问题讨论】:

  • 加密在进入您的数据库之前完成。

标签: c# mysql asp.net oracle visual-studio-2010


【解决方案1】:

你可以使用散列技术,

公共类安全 { 公共静态字符串HashSHA1(字符串值) { var sha1 = System.Security.Cryptography.SHA1.Create(); var inputBytes = Encoding.ASCII.GetBytes(value); 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();
}

}

在视觉工作室, cmd.Parameters.AddWithValue("@password", 密码);

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

// 将被存储为,

用户 ID |用户名 |密码

1 |冲积沉积 |我的密码

2 |冲积沉积 | F032680299B077AFB95093DE4082F625502B8251

【讨论】:

    【解决方案2】:

    存储密码的最佳和常用方法是,存储 密码hash 如下:-

    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

    希望这对您正在寻找的内容有很大帮助。

    【讨论】:

    • 感谢您的回复,我是把这段代码放到 sql 数据库中还是放到 Visual Studio 的某个地方?
    • 当您要保存数据时,必须在单击按钮时将上述代码添加到 Visual Studio 中。您还需要在 sql 表中创建一个列,其中将保存加密的密码。
    猜你喜欢
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    相关资源
    最近更新 更多