Decrypt from SHA256

后端 未结 2 1212
时光取名叫无心
时光取名叫无心 2020-12-10 05:37

I have that code to encrypt string to sha256 and next to base64:

 public static string Sha256encrypt(string phrase)
    {
        UTF8Encoding encoder = new          


        
相关标签:
2条回答
  • 2020-12-10 06:12

    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.

    0 讨论(0)
  • 2020-12-10 06:15

    It is impossible per se. SHA is a hash function, which implies it is one-way and used just for validation and similar things. Since the result of SHA-256 is of fixed length (256 bits) that also means that most of the information is lost when computing it.

    You can brute-force it though, meaning that you could try and compute hash of a large number of different inputs and see if the hash matches.

    Sometime in the future a cryptographic weakness may be found for SHA thus making it breakable but practically it is not a reversible function.

    See details about hash functions on Wikipedia.

    0 讨论(0)
提交回复
热议问题