Jus*_*tin 0 c# encryption vba md5
我正在C#为我的公司创建一个新的应用程序.
我们的SQL数据库存储的密码使用用户MD5加密这是通过我们使用其他应用程序创建MS Access在VBA.
我们使用本网站的代码 - http://www.di-mgt.com.au/crypto.html#MD5作为我们的VBA应用程序.
我在那个网站上看到我应该可以在另一个平台上解密密码:http://www.di-mgt.com.au/cryptoCrossPlatform.html
但我不知道我怎么能这样做C#.
我还查看了一些代码CodeProject- 但是解密会将不同的结果拉回到已存储在我们数据库中的内容.http://www.codeproject.com/Articles/38951/How-To-Hash-Data-Using-MD-and-SHA
如何在我的新C#应用程序中验证此登录?
编辑: 这是我现在正在使用的哈希.
/// <summary>
/// take any string and encrypt it using MD5 then
/// return the encrypted data
/// </summary>
/// <param name="data">input text you will enterd to encrypt it</param>
/// <returns>return the encrypted text as hexadecimal string</returns>
private string GetMD5HashData(string data)
{
//create new instance of md5
MD5 md5 = MD5.Create();
//convert the input text to array of bytes
byte[] hashData = md5.ComputeHash(Encoding.Default.GetBytes(data));
//create new instance of StringBuilder to save hashed data
StringBuilder returnValue = new StringBuilder();
//loop for each byte and add it to StringBuilder
for (int i = 0; i < hashData.Length; i++)
{
returnValue.Append(hashData[i].ToString());
}
// return hexadecimal string
return returnValue.ToString();
}
/// <summary>
/// encrypt input text using MD5 and compare it with
/// the stored encrypted text
/// </summary>
/// <param name="inputData">input text you will enterd to encrypt it</param>
/// <param name="storedHashData">the encrypted text
/// stored on file or database ... etc</param>
/// <returns>true or false depending on input validation</returns>
private bool ValidateMD5HashData(string inputData, string storedHashData)
{
//hash input text and save it string variable
string getHashInputData = GetMD5HashData(inputData);
if (string.Compare(getHashInputData, storedHashData) == 0)
{
return true;
}
else
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我们的SQL数据库存储的密码使用用户MD5加密这是通过我们使用其他应用程序创建
MS Access在VBA.
不,你没有.MD5不是加密,它是一个哈希函数.它也不太适合密码.您可能想要刹车并阅读如何在C#中安全地存储密码.
// Calculating a hash
string hash = BCrypt.HashPassword(usersPassword, BCrypt.GenerateSalt());
// Validating a hash
if (BCrypt.Verify(usersPassword, hash)) {
// Login successful
}
Run Code Online (Sandbox Code Playgroud)
简单,易于推理和安全.