public static function signAndEncrypt(
        HiddenString $message,
        SignatureSecretKey $secretKey,
        PublicKey $recipientPublicKey,
        $encoding = Halite::ENCODE_BASE64URLSAFE
    ): string {
        if ($recipientPublicKey instanceof SignaturePublicKey) {
            $publicKey = $recipientPublicKey->getEncryptionPublicKey();
        } elseif ($recipientPublicKey instanceof EncryptionPublicKey) {
            $publicKey = $recipientPublicKey;
        } else {
            // @codeCoverageIgnoreStart
            throw new InvalidKey('An invalid key type was provided');
            // @codeCoverageIgnoreEnd
        }
        $signature = self::sign($message->getString(), $secretKey, true);
        $plaintext = new HiddenString($signature . $message->getString());
        \sodium_memzero($signature);

        $myEncKey = $secretKey->getEncryptionSecretKey();
        return self::encrypt($plaintext, $myEncKey, $publicKey, $encoding);
    }
public static function signAndEncrypt(
        HiddenString $message,
        SignatureSecretKey $secretKey,
        PublicKey $recipientPublicKey,
        $encoding = Halite::ENCODE_BASE64URLSAFE
    ): string {
        if ($recipientPublicKey instanceof SignaturePublicKey) {
            $publicKey = $recipientPublicKey->getEncryptionPublicKey();
        } elseif ($recipientPublicKey instanceof EncryptionPublicKey) {
            $publicKey = $recipientPublicKey;
        } else {
            // @codeCoverageIgnoreStart
            throw new InvalidKey('An invalid key type was provided');
            // @codeCoverageIgnoreEnd
        }
        $signature = self::sign($message->getString(), $secretKey, true);
        $plaintext = new HiddenString($signature . $message->getString());
        \sodium_memzero($signature);

        $myEncKey = $secretKey->getEncryptionSecretKey();
        return self::encrypt($plaintext, $myEncKey, $publicKey, $encoding);
    }
public static function signAndEncrypt ( HiddenString $ message , SignatureSecretKey $ secretKey , PublicKey $ recipientPublicKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { if ( $ recipientPublicKey instanceof SignaturePublicKey ) { $ publicKey = $ recipientPublicKey -> getEncryptionPublicKey ( ) ; } elseif ( $ recipientPublicKey instanceof EncryptionPublicKey ) { $ publicKey = $ recipientPublicKey ; } else { // @codeCoverageIgnoreStart throw new InvalidKey ( 'An invalid key type was provided' ) ; // @codeCoverageIgnoreEnd } $ signature = self :: sign ( $ message -> getString ( ) , $ secretKey , true ) ; $ plaintext = new HiddenString ( $ signature . $ message -> getString ( ) ) ; \ sodium_memzero ( $ signature ) ; $ myEncKey = $ secretKey -> getEncryptionSecretKey ( ) ; return self :: encrypt ( $ plaintext , $ myEncKey , $ publicKey , $ encoding ) ; }
Sign a message then encrypt it with the recipient's public key.

@param HiddenString $message           Plaintext message to sign and encrypt
@param SignatureSecretKey $secretKey   Private signing key
@param PublicKey $recipientPublicKey   Public encryption key
@param string|bool $encoding           Which encoding scheme to use?
@return string

@throws CannotPerformOperation
@throws InvalidDigestLength
@throws InvalidKey
@throws InvalidMessage
@throws InvalidType
@throws \TypeError
Sign a message then encrypt it with the recipient s public key .