Search code examples
phpmcrypt

How can you override the 24 character mcrypt salt limit?


I would like to use a salt that has more than 24 characters with mcrypt.

mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND));

However if I make $salt greater than 24 characters it throws this warning and uses a truncated salt at 24 characters:

Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: Size of key is too large for this algorithm

Is there any way to get around this?


Solution

  • 24 is the limit of this alorithm. Chars over 24 characters isn't used. But you can always trasnform your salt.

    http://en.wikipedia.org/wiki/Advanced_Encryption_Standard