public static function verifyAndDecrypt(
        string $ciphertext,
        SignaturePublicKey $senderPublicKey,
        SecretKey $givenSecretKey,
        $encoding = Halite::ENCODE_BASE64URLSAFE
    ): HiddenString {
        if ($givenSecretKey instanceof SignatureSecretKey) {
            $secretKey = $givenSecretKey->getEncryptionSecretKey();
        } elseif ($givenSecretKey instanceof EncryptionSecretKey) {
            $secretKey = $givenSecretKey;
        } else {
            throw new InvalidKey('An invalid key type was provided');
        }
        $senderEncKey = $senderPublicKey->getEncryptionPublicKey();
        $decrypted = self::decrypt($ciphertext, $secretKey, $senderEncKey, $encoding);
        $signature = Binary::safeSubstr($decrypted->getString(), 0, SODIUM_CRYPTO_SIGN_BYTES);
        $message = Binary::safeSubstr($decrypted->getString(), SODIUM_CRYPTO_SIGN_BYTES);
        if (!self::verify($message, $senderPublicKey, $signature, true)) {
            throw new InvalidSignature('Invalid signature for decrypted message');
        }
        return new HiddenString($message);
    }
public static function verifyAndDecrypt(
        string $ciphertext,
        SignaturePublicKey $senderPublicKey,
        SecretKey $givenSecretKey,
        $encoding = Halite::ENCODE_BASE64URLSAFE
    ): HiddenString {
        if ($givenSecretKey instanceof SignatureSecretKey) {
            $secretKey = $givenSecretKey->getEncryptionSecretKey();
        } elseif ($givenSecretKey instanceof EncryptionSecretKey) {
            $secretKey = $givenSecretKey;
        } else {
            throw new InvalidKey('An invalid key type was provided');
        }
        $senderEncKey = $senderPublicKey->getEncryptionPublicKey();
        $decrypted = self::decrypt($ciphertext, $secretKey, $senderEncKey, $encoding);
        $signature = Binary::safeSubstr($decrypted->getString(), 0, SODIUM_CRYPTO_SIGN_BYTES);
        $message = Binary::safeSubstr($decrypted->getString(), SODIUM_CRYPTO_SIGN_BYTES);
        if (!self::verify($message, $senderPublicKey, $signature, true)) {
            throw new InvalidSignature('Invalid signature for decrypted message');
        }
        return new HiddenString($message);
    }
public static function verifyAndDecrypt ( string $ ciphertext , SignaturePublicKey $ senderPublicKey , SecretKey $ givenSecretKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : HiddenString { if ( $ givenSecretKey instanceof SignatureSecretKey ) { $ secretKey = $ givenSecretKey -> getEncryptionSecretKey ( ) ; } elseif ( $ givenSecretKey instanceof EncryptionSecretKey ) { $ secretKey = $ givenSecretKey ; } else { throw new InvalidKey ( 'An invalid key type was provided' ) ; } $ senderEncKey = $ senderPublicKey -> getEncryptionPublicKey ( ) ; $ decrypted = self :: decrypt ( $ ciphertext , $ secretKey , $ senderEncKey , $ encoding ) ; $ signature = Binary :: safeSubstr ( $ decrypted -> getString ( ) , 0 , SODIUM_CRYPTO_SIGN_BYTES ) ; $ message = Binary :: safeSubstr ( $ decrypted -> getString ( ) , SODIUM_CRYPTO_SIGN_BYTES ) ; if ( ! self :: verify ( $ message , $ senderPublicKey , $ signature , true ) ) { throw new InvalidSignature ( 'Invalid signature for decrypted message' ) ; } return new HiddenString ( $ message ) ; }
Decrypt a message, then verify its signature.

@param string $ciphertext                   Plaintext message to sign and encrypt
@param SignaturePublicKey $senderPublicKey  Private signing key
@param SecretKey $givenSecretKey            Public encryption key
@param string|bool $encoding                Which encoding scheme to use?
@return HiddenString

@throws CannotPerformOperation
@throws InvalidDigestLength
@throws InvalidKey
@throws InvalidMessage
@throws InvalidSignature
@throws InvalidType
@throws \TypeError
Decrypt a message then verify its signature .