0

mcrypt_encrypt(): Key of size 10 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported!

https://i.stack.imgur.com/qE1ZD.png

How can I fix this??

Ahmet Zeybek
  • 1,196
  • 1
  • 13
  • 24
  • 4
    obviously, provide a key of length 16, 24, or 32... – Marc B Jun 29 '15 at 21:08
  • @MarcB can you give me an example, i cant find anywhere :( – Ahmet Zeybek Jun 29 '15 at 21:10
  • nobody help on this site :( everybody knows everything... – Ahmet Zeybek Jun 29 '15 at 21:25
  • possible duplicate of [mcrypt\_decrypt() error change key size](http://stackoverflow.com/questions/27254432/mcrypt-decrypt-error-change-key-size) – Artjom B. Jun 29 '15 at 21:43
  • You haven't shown your complete code to reproduce the problem, but I think you confused a key with a passphrase. A key has specific sizes, but passphrases do not. You can get a key from a passphrase with a key derivation function of your choice. PBKDF2 is a popular choice. – Artjom B. Jun 29 '15 at 21:46

1 Answers1

6

Used to be if your key was too short that PHP would pad it with \0. This is no longer the case since PHP version 5.6.0. You should check how big required key is for the cipher being used: http://php.net/manual/en/function.mcrypt-get-key-size.php Note there are other ways to check key size, check the documentation. Simple way I understand key size: a string like 'fubar' in ASCII is 5 * 8 = 40 bytes (8 bytes per char). But that's making assumptions about character set in use. Some comments at php.net better explain how to roll a key of correct size:

$key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");

Here the 64 char string will be converted into 32 byte key because bc is a byte, b0 is another, etc. From http://php.net/manual/en/function.mcrypt-encrypt.php

You can double check number of bytes with strlen(). From above example strlen($key) will print out 32.

Tom Pimienta
  • 109
  • 3