note 55901 added to function.openssl-public-encrypt
| From: | ThomasHorsten at osu1 dot php dot net | Date: | Tue, 16 Aug 2005 23:21:10 +0000 |
| Subject: | note 55901 added to function.openssl-public-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93770@lists.php.net to get a copy of this message | ||
chsnyder writes that the data is limited to 936 bits in his implementation.
Actually, it has nothing to do with RSA being CPU intensive, RAM or anything of the sort.
Basically when you encrypt something using an RSA key (whether public or private), the encrypted
value must be smaller than the key (due to the maths used to do the actual encryption). So if you
have a 1024-bit key, in theory you could encrypt any 1023-bit value (or a 1024-bit value smaller
than the key) with that key.
However, the PKCS#1 standard, which OpenSSL uses, specifies a padding scheme (so you can encrypt
smaller quantities without losing security), and that padding scheme takes a minimum of 11 bytes (it
will be longer if the value you're encrypting is smaller). So the highest number of bits you
can encrypt with a 1024-bit key is 936 bits because of this (unless you disable the padding by
adding the OPENSSL_NO_PADDING flag, in which case you can go up to 1023-1024 bits). With a 2048-bit
key it's 1960 bits instead.
But as chsnyder correctly wrote, the normal application of a public key encryption algorithm is to
store a key or a hash of the data you want to respectively encrypt or sign. A hash is typically
128-256 bits (the PHP sha1() function returns a 160 bit hash). And an AES key is 128 to 256 bits. So
either of those will comfortably fit inside a single RSA encryption.
----
Manual Page -- http://www.php.net/manual/en/function.openssl-public-encrypt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55901
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55901&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55901&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55901&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55901&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55901&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55901&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55901&report=yes
Search -- http://master.php.net/manage/user-notes.php