简体   繁体   English

使用OpenSSL / PHP加密库从Windows加密API解密RSA

[英]Decrypt RSA from Windows Crypto API with OpenSSL/PHP Crypto Libs

I've developed a C application with a component that Encrypts a small plaintext with an RSA 2048 key. 我已经开发了一个C应用程序,其组件使用RSA 2048密钥对小的纯文本进行加密。 The encryption is done using the Windows Enhanced crypto api. 加密是使用Windows增强加密api完成的。 It seems to work perfectly and outputs a 128 byte Ciphertext to file. 它似乎可以正常工作,并向文件输出128字节的密文。

I have no idea what sort of cryptographic form the Ciphertext is in (Whether it's padded, encoding etc) (I'm just importing the public key and encryptiong with it (No extra settings)) 我不知道密文采用的是哪种加密形式(是否被填充,编码等)(我只是导入公共密钥并用它加密(没有其他设置))

Anyway I need to be able to decrypt the Ciphertext back to plaintext using the private key with a php script. 无论如何,我需要能够使用带有php脚本的私钥将密文解密为纯文本。

I've tried using openssl over command line during testing but I got a data greater than mod len error. 我在测试过程中尝试通过命令行使用openssl,但是得到的数据大于mod len错误。

Are there any transformations I need to do with the Ciphertext before trying to decrypt it or any settings I need to specify with the openssl_private_decrypt. 在尝试解密密文之前,是否需要对密文进行任何转换,或者是否需要使用openssl_private_decrypt指定任何设置。 (I currently have the private key in pem format but I can convert it to many more formats) (我目前拥有pem格式的私钥,但可以将其转换为更多格式)

Also any suggestions for other php libraries that might be more effective for this than openssl would be appreciated. 此外,对于其他比openssl更有效的php库的建议也将不胜感激。

Thanks. 谢谢。

If you want to decrypt the data using OpenSSL, reverse the data byte by byte. 如果要使用OpenSSL解密数据,请逐字节反转数据。 This is because OpenSSL considers them as big endian. 这是因为OpenSSL将它们视为大端字节。

This question may help you. 这个问题可能对您有帮助。 I faced similar problem for calculating hash. 我在计算哈希时遇到了类似的问题。 When I reversed the byte order, it works perfectly in OpenSSL. 当我反转字节顺序时,它可以在OpenSSL中完美运行。 So, this might help you. 因此,这可能对您有帮助。

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

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