Search code examples
phpmcrypt

How do I use MCRYPT in PHP to encode AES128 with IV?


Here is what I got:

$username = "username";
$password = "password";
$companyID = "companyID";

function encodeAES($u, $p, $c){
    $original = "$u,$p,$c";
    $key = "myKey";
    $IV = "00000000";
    return rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $original, MCRYPT_MODE_CBC, $IV)), "\0\3");
}

print encodeAES($username, $password, $companyID);

Error is:

Fatal error: Call to undefined function mcrypt_encrypt() on line 9

Solution

  • I faced same issue with PHP version 5.2.10, open up php.ini and allow the php_mycrypt.dll extension by removing the ;, i.e. changing:

    ;extension=php_mcrypt.dll to extension=php_mcrypt.dll