SHA512哈希到C#中的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12143986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SHA512 hash to string in C#
提问by Mr.V.
I have code to generate SHA512 from string.
我有从字符串生成 SHA512 的代码。
public static string GetCrypt(string text)
{
string hash = "";
SHA512 alg = SHA512.Create();
byte[] result = alg.ComputeHash(Encoding.UTF8.GetBytes(text));
hash = Encoding.UTF8.GetString(result);
return hash;
}
现在我必须将哈希转换回字符串。任何想法如何做到?谢谢你。采纳答案by Daniel A. White
Hashes are 1-way. You can't get it back (easily). you might want actual encryption.
哈希是 1 向的。你不能把它拿回来(很容易)。您可能需要实际的加密。
回答by Anirudha
You cant convert a hashback to string from which you computed the hash.
您不能将 a 转换hash回您计算散列的字符串。
If you want it then you would have to comparethe hash with each of the target strings hash.
如果你想要它,那么你必须将散列与每个目标字符串散列进行比较。
If one of them matches with the hash,then that hash comes from the target string.
如果其中之一与哈希匹配,则该哈希来自目标字符串。
Its use:If you want to store passwordsin database,you can store its hashes instead of passwords.So even if a hacker gets access to your database,he cant get the password cuz it is hashed.The only way to know the string through which we created the hash is to matchit with the desired string!
它的使用方法:如果你想存储passwords的database,可以存储其哈希值,而不是passwords.So即使黑客获得访问您的数据库,他不能得到密码cuz它是hashed.The只知道字符串的方式,通过它我们创建散列是为了将它与所需的字符串匹配!
回答by Gautam Jain
Yes. Hashes are one-way. Please use symmetric encryption classes like RijndaelManaged.
是的。哈希是单向的。请使用对称加密类,如 RijndaelManaged。
Here is a RijndaelSimple class that I am using: http://www.obviex.com/samples/encryption.asp
这是我正在使用的 RijndaelSimple 类:http: //www.obviex.com/samples/encryption.asp
The cached version of the same link is here: http://webcache.googleusercontent.com/search?q=cache:WyVau-XgIzkJ:www.obviex.com/samples/encryption.asp&hl=en&prmd=imvns&strip=1
相同链接的缓存版本在这里:http://webcache.googleusercontent.com/search?q=cache: WyVau-XgIzkJ: www.obviex.com/samples/encryption.asp&hl=en&prmd=imvns&strip=1

