从SHA256解密 [英] Decrypt from SHA256
本文介绍了从SHA256解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static string Sha256encrypt(string phrase)
{
UTF8Encoding encoder = new UTF8Encoding();
SHA256Managed sha256hasher = new SHA256Managed();
byte [] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(phrase));
return Convert.ToBase64String(hashedDataBytes);
}
如何解密我的密码在另一边?
解决方案
您无法解密单向哈希。您应该做的是将输入的密码的哈希与数据库中存储的哈希进行比较。
示例:
var password =1234;
var hashedPassword = Sha256encrypt(password);
var allowLogin = hashedPassword == storedPassword; // dataPassword from数据库等
这只是非常基础的,当使用散列算法时应考虑使用 Salt 。
I have that code to encrypt string to sha256 and next to base64:
public static string Sha256encrypt(string phrase)
{
UTF8Encoding encoder = new UTF8Encoding();
SHA256Managed sha256hasher = new SHA256Managed();
byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(phrase));
return Convert.ToBase64String(hashedDataBytes);
}
How can I decrypt my password in other side?
解决方案
You cannot decrypt the result of a One Way Hash. What you should do instead is compare a hash of the entered password versus the stored hash in the database.
Example:
var password = "1234";
var hashedPassword = Sha256encrypt(password);
var allowLogin = hashedPassword == storedPassword; //storedPassword from Database, etc.
This is only the very basics though, when using hashing algorithms you should consider using a Salt too.
这篇关于从SHA256解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文