php 试图解密 sha256 哈希
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2244559/
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
Trying to decrypt a sha256 hash
提问by james
Please I need your help, Here is my encryption codes in PHP, it works fine but I don't know how to decrypt it in PHP. I need to get the actual value back. I have similar code in c# and I was able to get the same results. But I need to decrypt the value.
请我需要你的帮助,这是我在 PHP 中的加密代码,它工作正常,但我不知道如何在 PHP 中解密它。我需要取回实际价值。我在 c# 中有类似的代码,我能够得到相同的结果。但我需要解密该值。
<?php
$DATA= 'james' ;
$KEY= 'moveme';
$hash = hash_hmac("sha256", utf8_encode($DATA), utf8_encode($KEY), false);
echo $hash;
?>
回答by Patrick
hash_hmac is a hashing function, not an encryption function. You won't be able to decrypt it.
hash_hmac 是散列函数,不是加密函数。你将无法解密它。
You should use the Mcrypt moduleinstead.
您应该改用Mcrypt 模块。
回答by GodsBoss
The SHA-256 hash functionis a hash function, it is not bijective. You cannot get your value back, neither in PHP nor in C#. Would be interesting to see this "working" C# code.
的SHA-256散列函数是一个散列函数,它不是双射。无论是在 PHP 中还是在 C# 中,您都无法取回您的价值。看到这个“有效”的 C# 代码会很有趣。
回答by Ronald D. Willis
If you need to be able to encrypt and decrypt information, read up on the mcrypt functions.
如果您需要能够加密和解密信息,请阅读 mcrypt 函数。

