从 SHA256 解密 [英] Decrypt from SHA256
本文介绍了从 SHA256 解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有将字符串加密为 sha256 和 base64 旁边的代码:
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?
推荐答案
您无法解密 One 的结果方式哈希.您应该做的是比较输入密码的哈希值与数据库中存储的哈希值.
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.
示例:
var password = "1234";
var hashedPassword = Sha256encrypt(password);
var allowLogin = hashedPassword == storedPassword; //storedPassword from Database, etc.
这只是最基本的,当使用散列算法时,你应该考虑使用 Salt 也是.
This is only the very basics though, when using hashing algorithms you should consider using a Salt too.
这篇关于从 SHA256 解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文