0

PHP 函数的 C# 等价物是openssl_public_decrypt什么?

我曾尝试使用 RSACryptoProvider,但 api 不允许我在没有私钥的情况下解密,

我需要创建所提供数据的哈希,然后与提供的签名进行比较

在 PHP 中

$key = openssl_get_publickey('provided_public_key'));
openssl_public_decrypt(base64_decode($_GET['signature']), $hashExpected, $key);

所以我的问题是如何在 c# 中生成 hashExpected?

谢谢

4

1 回答 1

0

There isn't one: the .NET Framework does not come with OpenSSL.

There is a wrapper for OpenSSL you can use from within .NET: http://openssl-net.sourceforge.net/ however it doesn't have a direct analog for openssl_public_decrypt as it provides a close wrapper.

.NET comes with the rich System.Cryptography namespace.

Looking at PHP's openssl source code (here: https://github.com/frice2014/php_source/blob/467ed5d6edff72219afd3e644516f131118ef48e/ext/openssl/php_openssl.c ) we see that openssl_public_decrypt calls RSA_public_decrypt, however this is an implementation detail. The documentation for PHP's openssl_public_decrypt function does not specify what algorithm it uses, so you cannot depend on data being read by other implementations of RSA, such as .NET's.

I'm assuming you're trying to write C# that is interopable with PHP, rather than outright replacing it. In which case I suggest changing your PHP implementation so you know exactly what crypto algorithms are in use (complete with any IV and cipher-block-mode), because without those you cannot get the two to reliably work together.

于 2013-03-22T00:32:18.537 回答