zoftdev
2009-06-05 05:19:22 UTC
Dear,
Please give me an advice , I don't sure it from OPENSSL or Java JCE
My problem is strange , java (private key) talk with php (public key )
in 2 way.
1. java encrypt -> php decrypt
2. php encrypt -> java decrypt
for (2) operation successfully.
but (1): php decryption get the NULL string
if I change from PKCS1Padding -> NoPadding then php can decypt message.
--------------
Java:
Cipher rsa_cipher =
Cipher.getInstance("RSA/ECB/PKCS1Padding");
rsa_cipher.init(Cipher.ENCRYPT_MODE,rsaPublicKey); // auto selects
block type 2
AlgorithmParameters pm = rsa_cipher.getParameters();
byte[] enc_data = rsa_cipher.doFinal(ciphertext.getBytes());
BASE64Encoder based64 = new BASE64Encoder();
s_out = based64.encode(enc_data); //ciphertext
---------------
PHP:
$split_ctext=substr($cipher_text,$i,$blocksize);
$split_ctext=str_replace( "\r\n", "", $split_ctext );
$split_ctext=str_replace( "\n", "", $split_ctext );
$split_ctext=base64_decode($split_ctext);
openssl_public_decrypt( $split_ctext, $tmp, $public_key);
------------
if I change to
Cipher rsa_cipher =
Cipher.getInstance("RSA/ECB/PKCS1Padding");
and
openssl_public_decrypt( $split_ctext, $tmp,
$public_key,OPENSSL_NO_PADDING);
Then I can success get plain text
---------------
Plain Text:
tmp =
"eitweb123|WEB|20090512104236||cpg_test|23022006145859|3199900071658|100|100|0|7||eitweb123|WEB|20090512104236||cpg_te";
Result:
Fail Case:
[null message]
Success Case:
�����������eitweb123|WEB|20090512104236||cpg_test|23022006145859|3199900071658|100|100|0|7||eitweb123|WEB|20090512104236||cpg_te
Please give me an advice , I don't sure it from OPENSSL or Java JCE
My problem is strange , java (private key) talk with php (public key )
in 2 way.
1. java encrypt -> php decrypt
2. php encrypt -> java decrypt
for (2) operation successfully.
but (1): php decryption get the NULL string
if I change from PKCS1Padding -> NoPadding then php can decypt message.
--------------
Java:
Cipher rsa_cipher =
Cipher.getInstance("RSA/ECB/PKCS1Padding");
rsa_cipher.init(Cipher.ENCRYPT_MODE,rsaPublicKey); // auto selects
block type 2
AlgorithmParameters pm = rsa_cipher.getParameters();
byte[] enc_data = rsa_cipher.doFinal(ciphertext.getBytes());
BASE64Encoder based64 = new BASE64Encoder();
s_out = based64.encode(enc_data); //ciphertext
---------------
PHP:
$split_ctext=substr($cipher_text,$i,$blocksize);
$split_ctext=str_replace( "\r\n", "", $split_ctext );
$split_ctext=str_replace( "\n", "", $split_ctext );
$split_ctext=base64_decode($split_ctext);
openssl_public_decrypt( $split_ctext, $tmp, $public_key);
------------
if I change to
Cipher rsa_cipher =
Cipher.getInstance("RSA/ECB/PKCS1Padding");
and
openssl_public_decrypt( $split_ctext, $tmp,
$public_key,OPENSSL_NO_PADDING);
Then I can success get plain text
---------------
Plain Text:
tmp =
"eitweb123|WEB|20090512104236||cpg_test|23022006145859|3199900071658|100|100|0|7||eitweb123|WEB|20090512104236||cpg_te";
Result:
Fail Case:
[null message]
Success Case:
�����������eitweb123|WEB|20090512104236||cpg_test|23022006145859|3199900071658|100|100|0|7||eitweb123|WEB|20090512104236||cpg_te
--
View this message in context: http://www.nabble.com/openssl-cannot-decrypt-the-%22RSA-ECB-PKCS1Padding%22-from-java-tp23881221p23881221.html
Sent from the OpenSSL - User mailing list archive at Nabble.com.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users-MCmKBN63+***@public.gmane.org
Automated List Manager majordomo-MCmKBN63+***@public.gmane.org
View this message in context: http://www.nabble.com/openssl-cannot-decrypt-the-%22RSA-ECB-PKCS1Padding%22-from-java-tp23881221p23881221.html
Sent from the OpenSSL - User mailing list archive at Nabble.com.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users-MCmKBN63+***@public.gmane.org
Automated List Manager majordomo-MCmKBN63+***@public.gmane.org