Even I too used the ECB in mycrypt_encrypt() function but the output is deferring.
Code snippet:
For Decryption:
PHP Code:
$iIVSize = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$strIV = mcrypt_create_iv( $iIVSize, MCRYPT_RAND );
$strPlaneText = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, $pSecKey, $pContent, MCRYPT_MODE_ECB, $strIV );
return rtrim( $strPlaneText, ( ( ord( substr( $strPlaneText, strlen( $strPlaneText ) - 1, 1 )) >= 0 and ord( substr( $strPlaneText, strlen( $strPlaneText ) - 1, 1 ) ) <= 32 ) ? chr( ord( substr( $strPlaneText, strlen( $strPlaneText ) - 1, 1 ) ) ): null ) );
For Encryption:
PHP Code:
$iIVSize = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$strIV = mcrypt_create_iv( $iIVSize, MCRYPT_RAND );
$pContent = str_pad( $pContent, ( 32*( floor( strlen( $pContent ) / 32 ) + ( strlen( $pContent ) % 32 == 0 ? 2 : 1 ) ) ), chr( 32 - ( strlen( $pContent ) % 32 ) ) );
$strCypherText = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $pSecKey, $pContent, MCRYPT_MODE_ECB, $strIV );
return $strCypherText;
But when I encrypt data with MySQL AES_ENCRYPT() function and decrypt the data with the function written in PHP with the same key it is not giving the correct output.
Bookmarks