Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

openssl encrypt problem

306 views
Skip to first unread message

Frédéric HARDY

unread,
Dec 16, 2003, 9:41:09 AM12/16/03
to
Hello !

I'm using openssl with php.

This is my code :

<?php

#GET PRIVATE KEY PREVIOUSLY GENERATED
$private_key = openssl_get_privatekey('file://path_to_private_key',
'mypassword');

$data = "
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx
yzabcdefghijklmnopqrstuvwxyzabcdefghijlm
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx
yzabcdefghijklmnopqrstuvwxyzabcdefghijlm
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx
yzabcdefghijklmnopqrstuvwxyzabcdefghijlm
";

$data = str_pad($data, 8192, '0');

openssl_private_encrypt($data, $crypted_text, $private_key);

echo 'String crypted: ' . urlencode($crypted_text) . '<BR/>';

#GET PUBLIC KEY
$public_key = openssl_get_publickey('file://path_to_certificate');

#DECRYPT
openssl_public_decrypt($crypted_text, $decrypted_text, $public_key);
echo 'String decrypted : ' . $decrypted_text;

#GET ERRORS
echo '<UL>';

while (($error = openssl_error_string()) !== false)
echo '<LI>' . $error . "</LI>";

echo '</UL>';

?>

And openssl say :

error:0406B06E:rsa routines:RSA_padding_add_none:data too large for key size
error:0407006A:rsa routines:RSA_padding_check_PKCS1_type_1:block type is not
01
error:04067072:rsa routines:RSA_EAY_PUBLIC_DECRYPT:padding check failed

I'm using windows 98, PHP 4.3.3 and OpenSSL 0.9.7b 10 Apr 2003.
I have the same result on freeBSD :-((

Have you got any solutions ???

Best regards,

Fred

===================================================================
Frederic HARDY Email: f...@hexanet.fr
HEXANET SARL URL: http://www.hexanet.fr/
ZAC Les Charmilles Tel: +33 (0)3 26 79 30 05
3, allée Thierry Sabine Direct: +33 (0)3 26 61 77 84
BP 202 - 51686 REIMS CEDEX 2 FRANCE
===================================================================

______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org

Jostein Tveit

unread,
Dec 17, 2003, 12:17:55 PM12/17/03
to
Frédéric HARDY <f...@hexanet.fr> writes:

> I'm using openssl with php.

I'm not familiar with the PHP interface to OpenSSL, but I may
give you some clues.

> error:0406B06E:rsa routines:RSA_padding_add_none:data too large for key size

The RSA key must be longer than the data you try to encrypt with
it.

> error:0407006A:rsa routines:RSA_padding_check_PKCS1_type_1:block type is not
> 01
> error:04067072:rsa routines:RSA_EAY_PUBLIC_DECRYPT:padding check failed

The encrypted data is not correctly padded.

--
Jostein Tveit (Jostei...@idi.ntnu.no)

0 new messages