使用SHA1的密码解密问题

时间:2016-05-18 06:44:16

标签: c# encryption cryptography sha1

我正在使用以下代码加密我的密码。

        public static string GetSHA1HashData(string password)
        {
            //create new instance of md5
            SHA1 sha1 = SHA1.Create();

            //convert the input text to array of bytes
            byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(password));

            //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();
        }

但我也想为Decryption创建代码。我试过了,但不是一个好的解决方案。你能帮我解决这个问题吗?

这里我使用了System.Security.Cryptography =&gt; SHA1:HashAlgorithm

提前致谢。

1 个答案:

答案 0 :(得分:4)

哈希值无法解密

  1. 哈希(比方说,只有256位),而String是任意(最多2GB),所以有很多{ {1}}具有相同的哈希值(歧义
  2. 哈希算法(SHA1)经过专门设计,是一个难以的任务,找出一个给定哈希值的字符串(复杂度
  3. 而不是解密比较哈希值:如果用户提供的密码具有与存储的哈希相同的相同哈希值,那么密码正确一个。

相关问题