Take the 2-minute tour ×

I need to create a public/private key, but I don't need big keys, I try to use the follow code:

$config = array('private_key_bits' => 128);
$res = openssl_pkey_new($config);

but I get this warning:

Warning: openssl_pkey_new(): private key length is too short; it needs to be at least 384 bits, not 64

Do I have to change something? (config files, modules etc etc?)

share|improve this question
Not needing big keys and needing small keys are two different things. Why not just use a bigger key? :) –  deceze Nov 22 '11 at 10:53
@deceze I have to save it in a cookie :-) I need a small key –  Dail Nov 22 '11 at 10:54
are you using the key for something that needs to be encrypted (ie needs to be kept secure)? –  MD-Tech Nov 22 '11 at 10:59
@MD-Tech sure, in mysql I have encypted data(users table), then I have a table where I put all the logged users, in this table I saved the ID and the password (to let the users decrypt his information) BUT i can put a plain password on this table, so I have created a pair of key private/public and encrupted that password with the public so the users with his private keywords can decrypt it and get the ORIGINAL password to decrypt the information on the users table. With this system I avoid the problem of storing a key to crypt/decrypt in the php files directly. –  Dail Nov 22 '11 at 11:07
the problem is that a key of that size will provide no security other than a tiny portion of obfuscation as the key will be breakable in minutes. If you need to keep the data secure a key of that length is pointless. I think there is probably a much better way to do what you are trying to achieve but I have to work out what it is you are trying to achieve in my head before I can suggest a solution –  MD-Tech Nov 22 '11 at 11:22
show 8 more comments

1 Answer

Upgraded to answer:

as I didnt know (I'm well away from web development currently!) I looked up the size limits on a cookie and they are 4kb each and you can create upto 20 per domain you should have space for a 1024 bit key even if you do have to use a dictionary lookup system between the cookies.

Also please make sure that the private key is sent using an ssl connection otherwise someone can intercept the private key and all your work will have been in vain

share|improve this answer
add comment

Your Answer


