public static function decrypt(
        string $ciphertext,
        SharedEncryptionKey $key
    ): string {
        $nonce = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 24);
        $result = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
            \ParagonIE_Sodium_Core_Util::substr($ciphertext, 24),
            $nonce,
            $nonce,
            $key->getString(true)
        );
        if (!\is_string($result)) {
            throw new InvalidMessageException('Message authentication failed.');
        }
        return $result;
    }
public static function decrypt(
        string $ciphertext,
        SharedEncryptionKey $key
    ): string {
        $nonce = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 24);
        $result = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
            \ParagonIE_Sodium_Core_Util::substr($ciphertext, 24),
            $nonce,
            $nonce,
            $key->getString(true)
        );
        if (!\is_string($result)) {
            throw new InvalidMessageException('Message authentication failed.');
        }
        return $result;
    }
public static function decrypt ( string $ ciphertext , SharedEncryptionKey $ key ) : string { $ nonce = \ ParagonIE_Sodium_Core_Util :: substr ( $ ciphertext , 0 , 24 ) ; $ result = \ ParagonIE_Sodium_Compat :: crypto_aead_xchacha20poly1305_ietf_decrypt ( \ ParagonIE_Sodium_Core_Util :: substr ( $ ciphertext , 24 ) , $ nonce , $ nonce , $ key -> getString ( true ) ) ; if ( ! \ is_string ( $ result ) ) { throw new InvalidMessageException ( 'Message authentication failed.' ) ; } return $ result ; }
Simple authenticated decryption
XChaCha20-Poly1305

@param string $ciphertext
@param SharedEncryptionKey $key
@return string
@throws InvalidMessageException
Simple authenticated decryption XChaCha20 - Poly1305