简体   繁体   English

使用PHP从.NET进行RSA解密

[英]RSA decryption from .NET using PHP

I am not sure where to post this so I am starting here and hoping for the best. 我不确定要在哪里发布,所以我从这里开始,希望能做到最好。 I have a public and private key generated for .NET. 我有一个为.NET生成的公钥和私钥。 The keys have (Modulus, Exponent, etc...). 键有(模量,指数等)。 I sent the public key to a third party and they used it to encrypt passwords in a database. 我将公钥发送给第三方,他们使用它来加密数据库中的密码。 I downloaded the encrypted passwords and now I need to decrypt them on my end. 我下载了加密的密码,现在需要对它们进行解密。 The issue comes in when it has to be decrypted on a unix server. 当必须在UNIX服务器上对其进行解密时,就会出现此问题。 I do not care if I use php, java or any other language as long as it works on the unix box. 我不在乎是否使用php,java或任何其他语言,只要它在unix框上有效即可。 I am a complete rookie to RSA keys and would appreciate any help or even a direction on where I "should" post this. 我是RSA密钥的完整新手,非常感谢我提供的任何帮助,甚至对我应该在哪里发布的内容都提供了指导。 Thanks in advance.... 提前致谢....

The values appear to be base64 encoded. 该值似乎是base64编码的。 You could use phpseclib's pure PHP RSA implementation and do something like this to load the public key: 您可以使用phpseclib的纯PHP RSA实现,并执行以下操作来加载公钥:

$rsa->loadKey(array('modulus' => $modulus, 'exponent' => $exponent), CRYPT_RSA_PUBLIC_FORMAT_RAW);

For the private key... maybe you could do something like.. 对于私钥...也许您可以做类似的事情..

$rsa = new Crypt_RSA();
$rsa->modulus = $modulus;
$rsa->publicExponent = $exponent;
$rsa->exponents = array(1=> $dp, $dq)
$rsa->coefficients = array(2 => $inverseq);
$rsa->primes = array(1 => $p, $q);

Or something like that - I haven't tested the code, but a cursory glance of phpseclib's code suggests that'll work. 或类似的东西-我还没有测试代码,但是粗略浏览一下phpseclib的代码就可以了。

有一篇很好的文章介绍了如何在PHP中使用.NET的密钥格式: 使用PHP通过.NET XML RSA密钥对数据进行加密/解密/签名/验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM