将哈希值更改回文本 [英] Changing hash back to text

查看:350
本文介绍了将哈希值更改回文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将密码设置为哈希并作为varchar存储到数据库中

但我想检索并将其转换回文本,因为它是

怎么做我这样做



继承人我怎么把它转换为哈希:



我试过的:



I have setup my password as hash and stored into the database as a varchar
But i want to retrieve and convert it back to text as it was
How do i do it

Heres how i converted it to hash:

What I have tried:

protected string MD5Hash(string input)
{
    StringBuilder stringBuilder = new StringBuilder();
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] bytes = md5.ComputeHash(new UTF8Encoding().GetBytes(input));
    for (int i = 0; i < bytes.Length; i++)
    {
        stringBuilder.Append(bytes[i].ToString("x2"));
    }
    return stringBuilder.ToString();

}

推荐答案

根据定义,哈希不能转换回原始哈希值。



您可以做的是散列一个新字符串并比较两个哈希值。如果它们匹配,那么新字符串就是旧字符串之前的字符串。
A hash by definition cannot be converted back to the original.

What you can do is hash a new string and compare the two hashes. If they match then the new string is what the old one was before it was hashed.


Quote:

我已将密码设置为哈希并作为varchar存储到数据库中

但是我想检索并将其转换回文本原样

我该怎么办它

I have setup my password as hash and stored into the database as a varchar
But i want to retrieve and convert it back to text as it was
How do i do it



简答:你不能!

MD5哈希是一个单向进程,就像任何其他哈希一样。你不能逆转它,它是设计的。

与可以解密的加密相反。


Short answer: you can't !
MD5 hash is a one way process, like any other hash. you can't reverse it, it is by design.
Contrary to encryption which can be decrypted.


你无法从哈希中获取原始数据。那是设计上的。如果需要解密,则必须使用加密方法而不是哈希。
You can't get the original data from a hash. That is by design. If you need to decrypt, you have to use an encryption method instead of a hash.


这篇关于将哈希值更改回文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆