On Mon, Dec 15, 2008, BiGNoRm6969 wrote:

> 
> Hi, the OpenSSL documentation tells : 
> 
> "RSA_public_encrypt() encrypts the flen bytes at from (usually a session
> key) using the public key rsa and stores the ciphertext in to. to must point
> to RSA_size(rsa) bytes of memory. "
> 
> 
> I made a test and I saw something strange. I used theses arrays for my
> tests:
> 
> unsigned char* test1 = new unsigned char[5];
> test1[0] = 'a';
> test1[1] = 'b';
> test1[2] = 'c';
> test1[3] = 'd';
> test1[4] = 'e';
> 
> unsigned char* test2 = new unsigned char[4];
> test2[0] = 'a';
> test2[1] = 'b';
> test2[2] = 'c';
> test2[3] = 'd';
> 
> 
> Here is my test:
> 
> RSA_public_encrypt(4, test1, encryptedLine1, publicKey, RSA_PKCS1_PADDING);
> RSA_public_encrypt(4, test2, encryptedLine2, publicKey, RSA_PKCS1_PADDING);
> 
> The two results (stored in encryptedLineX...) are not the same and I don't
> understand why.  The first argument is not supposed to be the length (in
> bytes)  of the data to be encrypted ? So in the two cases, the encryption is
> not supposed to bo on caracter 1 to 4 !?
> 

This is expected behaviour and is due to the nature of that padding mode. It
includes some pseudo random data which is different on each invocation. So
even if you encrypt the same data using the same key you will get a different
output each time.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to