public function encryptMessage($input)
    {
        $input = (string)$input;
        
        $calgo = $this->config->getCipherAlgorithm();
        $cmode = $this->config->getCipherMode();
        $malgo = $this->config->getHmacAlgorithm();
        
        $size = mcrypt_get_iv_size($calgo, $cmode);
        $keySize = mcrypt_get_key_size($calgo, $cmode);
        $blockSize = mcrypt_get_block_size($calgo, $cmode);
        $hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));
        
        $iv = random_bytes($size);
        $key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
        
        // PKCS7 Padding
        $pad = $blockSize - (strlen($input) % $blockSize);
        $input .= str_repeat(chr($pad), $pad);
        
        $cipherText = $iv . mcrypt_encrypt($calgo, $key, $input, $cmode, $iv);
        
        return $cipherText . hash_hmac($malgo, $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
    }
public function encryptMessage($input)
    {
        $input = (string)$input;
        
        $calgo = $this->config->getCipherAlgorithm();
        $cmode = $this->config->getCipherMode();
        $malgo = $this->config->getHmacAlgorithm();
        
        $size = mcrypt_get_iv_size($calgo, $cmode);
        $keySize = mcrypt_get_key_size($calgo, $cmode);
        $blockSize = mcrypt_get_block_size($calgo, $cmode);
        $hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));
        
        $iv = random_bytes($size);
        $key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
        
        // PKCS7 Padding
        $pad = $blockSize - (strlen($input) % $blockSize);
        $input .= str_repeat(chr($pad), $pad);
        
        $cipherText = $iv . mcrypt_encrypt($calgo, $key, $input, $cmode, $iv);
        
        return $cipherText . hash_hmac($malgo, $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
    }
public function encryptMessage ( $ input ) { $ input = ( string ) $ input ; $ calgo = $ this -> config -> getCipherAlgorithm ( ) ; $ cmode = $ this -> config -> getCipherMode ( ) ; $ malgo = $ this -> config -> getHmacAlgorithm ( ) ; $ size = mcrypt_get_iv_size ( $ calgo , $ cmode ) ; $ keySize = mcrypt_get_key_size ( $ calgo , $ cmode ) ; $ blockSize = mcrypt_get_block_size ( $ calgo , $ cmode ) ; $ hmacSize = strlen ( hash_hmac ( $ malgo , '' , 'foo-key' , true ) ) ; $ iv = random_bytes ( $ size ) ; $ key = $ this -> computeCipherKey ( $ this -> config -> getCipherKey ( ) , $ keySize , $ iv ) ; // PKCS7 Padding
 $ pad = $ blockSize - ( strlen ( $ input ) % $ blockSize ) ; $ input .= str_repeat ( chr ( $ pad ) , $ pad ) ; $ cipherText = $ iv . mcrypt_encrypt ( $ calgo , $ key , $ input , $ cmode , $ iv ) ; return $ cipherText . hash_hmac ( $ malgo , $ cipherText , $ this -> computeCipherKey ( $ this -> config -> getHmacKey ( ) , $ hmacSize , $ iv ) , true ) ; }
Encrypts the given message and adds an authenticity code.

<pre><b>CIPHERTEXT</b> := IV + ENCRYPT(CLEARTEXT, PBKDF(ENCRYPTION_KEY))
<b>MESSAGE</b> := CIPHERTEXT + HMAC(CIPHERTEXT, PBKDF(HMAC_KEY))
</pre>

@param string $input Plaintext message.
@return string Encrypted message.
Encrypts the given message and adds an authenticity code .