note 89831 deleted from function.mcrypt-module-open by thiago
| From: | thiago@php.net | Date: | Wed, 25 Mar 2009 11:54:01 +0000 |
| Subject: | note 89831 deleted from function.mcrypt-module-open by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152418@lists.php.net to get a copy of this message | ||
Note Submitter: royconejo
----
about the previous comments on hex formatting and capitalization as a way to improve the key:
this would seem pretty obvious, but it is a choice to be limited to only hex characters ([0-9a-z]);
you can get the original RAW output from md5() or sha1() and not the default readable hex
formatting.
the result of a raw output will be 16 o 20 (depending on the hash function being used) series of
chars in the range 0-255. way better than [0-9a-z] and even [0-9a-zA-Z].
16 or 20 is generally lower than the maximum key lenght ($ks in the example), but you can append two
or more keys together:
<?php
$human_key1 = 'something very secret';
$human_key2 = 'something else very secret';
// 40 bytes binary key using two "human readable" keys and sha1.
$bigger_binary_key = sha1($human_key1, true) . sha1($human_key2, true);
// then just use it as you would (extract taken from the example)
$key = substr($bigger_binary_key, 0, $ks);
?>
... or you can automatically split one large "human key" into two or more parts, hash
those parts with sha1 (raw output!) and merge them together again (in original order or rearrange,
salt, transform them as you like) to get a binary key of 40, 60, 80 or more chars depending on the
number of parts the secret key has been splitted =)