[英]java & phpseclib, RSA and OAEP?
I am encrypting in Java using Cipher.getInstance("RSA/ECB/OAEPWITHSHA-512ANDMGF1PADDING")
and setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP)
in phpseclib, but the phpseclib is not decrypting the data correctly. 我使用Cipher.getInstance("RSA/ECB/OAEPWITHSHA-512ANDMGF1PADDING")
和setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP)
在Java中加密,但是phpseclib没有正确解密数据。
It worked perfectly when I used RSA/ECB/PKCS1Padding
in Java, and setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1)
in phpseclib. 当我在Java中使用RSA/ECB/PKCS1Padding
和在phpseclib中使用setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1)
时,它工作得很好。
Here are the supported ciphers in Java: http://download.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html#SunJCEProvider 以下是Java中支持的密码: http : //download.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html#SunJCEProvider
Are none of those ciphers compatible with phpseclib's OAEP implementation? 这些密码中没有一个与phpseclib的OAEP实现兼容吗?
The problem lies in the size of the keys used, had me puzzled for a while as well. 问题在于使用的键的大小,让我困惑了一段时间。
To use OAEP safely, you have to use >=2048 bit RSA keys. 要安全地使用OAEP,您必须使用> = 2048位RSA密钥。
Also, make sure you run 另外,请确保您运行
$rsa->setHash('sha512');
$rsa->setMGFHash('sha512');
before setEncryptionMode() on the PHP side. 在PHP端的setEncryptionMode()之前。
edit : it seems 1024 keys won't work correctly even with sha256, so I've modified my answer to only include the safe 2048+ bits route. 编辑 :即使使用sha256,似乎1024键也无法正常工作,所以我修改了我的答案,只包括安全的2048+位路由。
You'd probably have to do $rsa->setHash('sha512'); 你可能不得不做$ rsa-> setHash('sha512'); By default sha1 is used. 默认情况下使用sha1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.