On Mon, Jan 19, 2004, IndiWEB - Jochen Roendigs wrote:

> Hi,
> 
> if I encrypt the same data with the same public key I get different
> encrypted data back which I (in 9 of 10 cases) cannot decrypt with my
> private key. Here's the details:
> 
> $string="Some Important Data"; // <- This is what I want to encrypt
> $fp=fopen ("server.crt","r"); // read the public key
> $pub_key=fread ($fp,8192);
> fclose($fp);
> $PK="";
> $PK=openssl_get_publickey($pub_key);
> if (!$PK) {
>    echo "Cannot get public key $pub_key";
> }
> 
> $finaltext1="";
> $finaltext2="";
> $finaltext3="";
> openssl_public_encrypt($string,$finaltext1,$PK); // encrypt string with
> key $PK
> openssl_public_encrypt($string,$finaltext2,$PK); // encrypt string with
> key $PK (2nd time)
> openssl_public_encrypt($string,$finaltext3,$PK); // encrypt string with
> key $PK (3rd time)
> print "       <HR>$finaltext<HR><BR>
>       <HR>$finaltext2<HR><BR>
>       <HR>$finaltext3<HR><BR>";
> 
> Maybe I'm wrong but shouldn't $finaltext1 be the same as $finaltext2 and
> $finaltext3 ??
> 

No. The PKCS#1 standard includes some random data when using RSA encryption so
you'll get a different answer each time: this is to defeat certain attacks.

The output data will also not in general be null terminated and can contain
embedded nulls, so the use of normal string manipulation routines wont work.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to