src/_Libs/_Crypt.php
public static function _encryptAESPKCS7($str, $key = _CryptConfig::AES_KEY, $cipher = _CryptConfig::CIPHER, $mode = _CryptConfig::MODE) {
        $key = self::_chopKeyForAES($key);
        $block = mcrypt_get_block_size($cipher, $mode);
        $pad = $block - (strlen($str) % $block);
        $str .= str_repeat(chr($pad), $pad);
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_DEV_URANDOM);
        $encrypted = mcrypt_encrypt($cipher, $key, $str, $mode, $iv);
        $ret = base64_encode($iv) . base64_encode($encrypted);
        return $ret;
    }
public static function _encryptAESPKCS7($str, $key = _CryptConfig::AES_KEY, $cipher = _CryptConfig::CIPHER, $mode = _CryptConfig::MODE) {
        $key = self::_chopKeyForAES($key);
        $block = mcrypt_get_block_size($cipher, $mode);
        $pad = $block - (strlen($str) % $block);
        $str .= str_repeat(chr($pad), $pad);
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_DEV_URANDOM);
        $encrypted = mcrypt_encrypt($cipher, $key, $str, $mode, $iv);
        $ret = base64_encode($iv) . base64_encode($encrypted);
        return $ret;
    }
public static function _encryptAESPKCS7 ( $ str , $ key = _CryptConfig :: AES_KEY , $ cipher = _CryptConfig :: CIPHER , $ mode = _CryptConfig :: MODE ) { $ key = self :: _chopKeyForAES ( $ key ) ; $ block = mcrypt_get_block_size ( $ cipher , $ mode ) ; $ pad = $ block - ( strlen ( $ str ) % $ block ) ; $ str .= str_repeat ( chr ( $ pad ) , $ pad ) ; $ iv = mcrypt_create_iv ( mcrypt_get_iv_size ( $ cipher , $ mode ) , MCRYPT_DEV_URANDOM ) ; $ encrypted = mcrypt_encrypt ( $ cipher , $ key , $ str , $ mode , $ iv ) ; $ ret = base64_encode ( $ iv ) . base64_encode ( $ encrypted ) ; return $ ret ; }
Encrypts a string using AES encryption with PKCS7 padding.
Random IV is used

Adapted from comments in PHP manual:
http://php.net/manual/en/function.mcrypt-encrypt.php

@param string $str The string to encrypt
@param string $key (optional) The private key to encrypt with (note: anything over 24 chars will be chopped off)
@param const $cipher (optional) One of the MCRYPT_RIJNDAEL_ ciphers
@param cont $mode (optional) One of the MCRYPT_MODE modes
@return string The encrypted string
Encrypts a string using AES encryption with PKCS7 padding . Random IV is used