C# c语言中的aes解密
因此,我为连接到我的数据库的c编写了这个登录脚本,但我想知道如何解密数据库,因为我当前的数据库使用aes加密,我希望程序对其进行解密,以便我能够回答正确的用户名和密码,但是任何有权访问数据库的人都会看到随机字符串,提前感谢通常您不需要使用AES加密密码,如果您这样做,则不需要将密码解密回来-您必须将AES密钥存储在某个位置,这可能是不安全的 相反,只需对原始密码应用一些加密哈希函数SHA2,并将此哈希存储在数据库中 当用户输入密码时-您正在将此哈希函数应用于用户输入的密码,这将为您提供哈希。 然后,您只需将此哈希值与保存在数据库中的哈希值进行比较C# c语言中的aes解密,c#,encryption,C#,Encryption,因此,我为连接到我的数据库的c编写了这个登录脚本,但我想知道如何解密数据库,因为我当前的数据库使用aes加密,我希望程序对其进行解密,以便我能够回答正确的用户名和密码,但是任何有权访问数据库的人都会看到随机字符串,提前感谢通常您不需要使用AES加密密码,如果您这样做,则不需要将密码解密回来-您必须将AES密钥存储在某个位置,这可能是不安全的 相反,只需对原始密码应用一些加密哈希函数SHA2,并将此哈希存储在数据库中 当用户输入密码时-您正在将此哈希函数应用于用户输入的密码,这将为您提供哈希。 然
因此,您根本不需要解密密码。您应该阅读经过盐渍、哈希处理的密码。不要只使用任何哈希函数。使用一种专门设计的密码散列,例如bcrypt.@Codo合理添加,我添加了关于加密散列函数的注释,而不仅仅是任何注释。但我不确定bcrypt是否比我最初建议的SHA2更合适。bcrypt更合适。它使用几轮来实现每哈希大约100毫秒的成本,这是黑客高成本和It系统低成本之间的一个很好的折衷。此外,它还返回一个方便的字符串,其中包括salt和所有其他bcrypt参数。如果您使用SHA2,您必须自己构建所有这些。顺便说一句:您的答案没有提到盐渍,盐渍是必不可少的。通过Rfc2898DeriveBytes的PBKDF2是.NET上最合适的KDF收件箱
using System;
using System.Data.OleDb;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con = new OleDbConnection();
string dbprovider;
string dbsource;
DataSet ds = new DataSet();
string username = "";
string password = "";
private void textBox1_TextChanged(object sender, EventArgs e)
{
username = textBox1.Text;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabPage2);
// TODO: This line of code loads data into the 'login_data1DataSet.Table1' table. You can move, or remove it, as needed.
this.table1TableAdapter.Fill(this.login_data1DataSet.Table1);
}
private void button1_Click(object sender, EventArgs e)
{
dbprovider = "Provider=Microsoft.ACE.OLEDB.12.0;"; //If you’re an avid fan of Google you’ll see this line written in a number of different ways, version 12(this one) is suitable for our version of access.
dbsource = "Data Source = ../login data1.accdb"; //Change this for the location and name of your db.
con.ConnectionString = dbprovider + dbsource;
con.Open(); //If you get this far you’re db is now opened successfully.
OleDbCommand command = new OleDbCommand("SELECT username FROM table1 WHERE username = @username", con);
command.Parameters.AddWithValue("@username", textBox1.Text);
OleDbDataReader reader = command.ExecuteReader();
if (!reader.HasRows)
{
MessageBox.Show("your username was not right");
reader.Close();
command.Dispose();
}
else
{
username = textBox1.Text;
reader.Close();
OleDbCommand command2 = new OleDbCommand("SELECT password FROM table1 WHERE password = @password", con);
command2.Parameters.AddWithValue("@password", textBox2.Text);
command2.Parameters.AddWithValue("@username", textBox1.Text);
OleDbDataReader reader2 = command2.ExecuteReader();
if (!reader2.HasRows)
{
// if (reader2.ToString != textBox2.Text)
MessageBox.Show("your password was not right");
}
else
{
MessageBox.Show("logged in");
tabControl1.TabPages.Insert(1,tabPage2);
password = textBox2.Text;
}
reader2.Close();
command2.Dispose();
}
con.Close();
}
}
}