return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, md5($key)));
I got warning msg like
Warning: mcrypt_encrypt(): Size of key is too large for this algorithm
How to solve this? Thanks in advance
Best How To :
Your key is too long, just like the warning message indicates.
As of 5.6.0,
iv sizes are no longer accepted.
mcrypt_encrypt() will now throw a warning and return
FALSE if the inputs are invalid. Previously keys and IVs were padded with
'\0' bytes to the next valid size.
The key size for AES-256 is 32 bytes; your string is 40 characters in length.
Also, look at Example 1 on that page. It indicates that
the key should be random binary, use scrypt, bcrypt or PBKDF2 to convert a string into a key
That means, don't use a string directly as the key (like you're doing). Not only is a key-derivation function more secure, but it will allow you to use any length of passphrase you wish, while generating the correct key length.