public static function decryptMessage($message, $key, $hashKey = '')
    {
        // Test the message and key for string validity.
        Helpers::isString($message, 'Encryption', 'decryptMessage');
        Helpers::isString($key, 'Encryption', 'decryptMessage');
        Helpers::isString($hashKey, 'Encryption', 'decryptMessage');
        // Create a special hashed key for encryption.
        $key = Hash::hash($key, $hashKey, Constants::SECRETBOX_KEYBYTES);
        // Validate and decode the paylload.
        $payload = self::getJsonPayload($message);
        $nonce = base64_decode($payload['nonce']);
        $ciphertext = base64_decode($payload['ciphertext']);
        // Open the secret box using the data provided.
        $plaintext = \Sodium\crypto_secretbox_open($ciphertext, $nonce, $key);
        // Test if the secret box returned usable data.
        if ($plaintext === false) {
            throw new Exceptions\DecryptionException("Failed to decrypt message using key.");
        }
        return unserialize($plaintext);
    }
public static function decryptMessage($message, $key, $hashKey = '')
    {
        // Test the message and key for string validity.
        Helpers::isString($message, 'Encryption', 'decryptMessage');
        Helpers::isString($key, 'Encryption', 'decryptMessage');
        Helpers::isString($hashKey, 'Encryption', 'decryptMessage');
        // Create a special hashed key for encryption.
        $key = Hash::hash($key, $hashKey, Constants::SECRETBOX_KEYBYTES);
        // Validate and decode the paylload.
        $payload = self::getJsonPayload($message);
        $nonce = base64_decode($payload['nonce']);
        $ciphertext = base64_decode($payload['ciphertext']);
        // Open the secret box using the data provided.
        $plaintext = \Sodium\crypto_secretbox_open($ciphertext, $nonce, $key);
        // Test if the secret box returned usable data.
        if ($plaintext === false) {
            throw new Exceptions\DecryptionException("Failed to decrypt message using key.");
        }
        return unserialize($plaintext);
    }
public static function decryptMessage ( $ message , $ key , $ hashKey = '' ) { // Test the message and key for string validity. Helpers :: isString ( $ message , 'Encryption' , 'decryptMessage' ) ; Helpers :: isString ( $ key , 'Encryption' , 'decryptMessage' ) ; Helpers :: isString ( $ hashKey , 'Encryption' , 'decryptMessage' ) ; // Create a special hashed key for encryption. $ key = Hash :: hash ( $ key , $ hashKey , Constants :: SECRETBOX_KEYBYTES ) ; // Validate and decode the paylload. $ payload = self :: getJsonPayload ( $ message ) ; $ nonce = base64_decode ( $ payload [ 'nonce' ] ) ; $ ciphertext = base64_decode ( $ payload [ 'ciphertext' ] ) ; // Open the secret box using the data provided. $ plaintext = \ Sodium \ crypto_secretbox_open ( $ ciphertext , $ nonce , $ key ) ; // Test if the secret box returned usable data. if ( $ plaintext === false ) { throw new Exceptions \ DecryptionException ( "Failed to decrypt message using key." ) ; } return unserialize ( $ plaintext ) ; }
Returns the encrypted message in plaintext format.

@param string $message The encrypted message portion.
@param string $key The encryption key used with the message.
@param string $hashKey The key to hash the key with.
@return string The encrypted message in plaintext format.
@throws Exceptions\DecryptionException
@throws Exceptions\InvalidTypeException
@throws Exceptions\OutOfRangeException
Returns the encrypted message in plaintext format .