如何将Hashcode(SHA1)转换为字符串 [英] How to Convert Hashcode(SHA1) to string
本文介绍了如何将Hashcode(SHA1)转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了Hash algaritham类型sha1。我将普通字符串转换为Hashcode,它工作正常。但我希望HashCode正常字符串。
我使用此代码将字符串转换为哈希码。
Hi,
I used Hash algaritham type "sha1". I convert normal string to Hashcode, it is working fine.But I want HashCode to normal string.
I used this code for string to hashcode.
public static string GenerateHash(string pwd, string saltAsBase64)
{
byte[] p1 = Convert.FromBase64String(saltAsBase64);
return GenerateHash(pwd, p1);
}
public static string GenerateHash(string pwd, byte[] saltAsByteArray)
{
System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] p1 = saltAsByteArray;
byte[] p2 = System.Text.Encoding.Unicode.GetBytes(pwd);
byte[] data = new byte[p1.Length + p2.Length];
p1.CopyTo(data, 0);
p2.CopyTo(data, p1.Length);
byte[] result = sha.ComputeHash(data);
string res = Convert.ToBase64String(result);
return res;
}
如果有人知道请帮帮我。
谢谢
vikranth
If any one know please help me.
Thanks
vikranth
推荐答案
将SAH1哈希转换为字符串是不可能的。 HASH是算法而不是编码器。找到价值的唯一方法是蛮力。如果您没有盐,可以试试彩虹表。
It is impossible to convert a SAH1 Hash to string. A HASH is an algorithm not an encoder. The only way to find what the value is, is by brute force. If you don't have a salt you can try rainbow tables.
这篇关于如何将Hashcode(SHA1)转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文