public static function encrypt($message, $key, $encode = false)
    {
        list($encKey, $authKey) = self::splitKeys($key);

        // Pass to UnsafeCrypto::encrypt
        $ciphertext = parent::encrypt($message, $encKey);

        // Calculate a MAC of the IV and ciphertext
        $mac = hash_hmac(self::HASH_ALGO, $ciphertext, $authKey, true);

        if ($encode) {
            return base64_encode($mac.$ciphertext);
        }
        // Prepend MAC to the ciphertext and return to caller
        return $mac.$ciphertext;
    }
public static function encrypt($message, $key, $encode = false)
    {
        list($encKey, $authKey) = self::splitKeys($key);

        // Pass to UnsafeCrypto::encrypt
        $ciphertext = parent::encrypt($message, $encKey);

        // Calculate a MAC of the IV and ciphertext
        $mac = hash_hmac(self::HASH_ALGO, $ciphertext, $authKey, true);

        if ($encode) {
            return base64_encode($mac.$ciphertext);
        }
        // Prepend MAC to the ciphertext and return to caller
        return $mac.$ciphertext;
    }
public static function encrypt ( $ message , $ key , $ encode = false ) { list ( $ encKey , $ authKey ) = self :: splitKeys ( $ key ) ; // Pass to UnsafeCrypto::encrypt $ ciphertext = parent :: encrypt ( $ message , $ encKey ) ; // Calculate a MAC of the IV and ciphertext $ mac = hash_hmac ( self :: HASH_ALGO , $ ciphertext , $ authKey , true ) ; if ( $ encode ) { return base64_encode ( $ mac . $ ciphertext ) ; } // Prepend MAC to the ciphertext and return to caller return $ mac . $ ciphertext ; }
Encrypts then MACs a message

@param string $message - plaintext message
@param string $key - encryption key (raw binary expected)
@param boolean $encode - set to TRUE to return a base64-encoded string
@return string (raw binary)
Encrypts then MACs a message