src/Crypto/DecryptionTrait.php
protected function decrypt(
        $cipherText,
        MaterialsProvider $provider,
        MetadataEnvelope $envelope,
        array $cipherOptions = []
    ) {
        $cipherOptions['Iv'] = base64_decode(
            $envelope[MetadataEnvelope::IV_HEADER]
        );

        $cipherOptions['TagLength'] =
            $envelope[MetadataEnvelope::CRYPTO_TAG_LENGTH_HEADER] / 8;

        $cek = $provider->decryptCek(
            base64_decode(
                $envelope[MetadataEnvelope::CONTENT_KEY_V2_HEADER]
            ),
            json_decode(
                $envelope[MetadataEnvelope::MATERIALS_DESCRIPTION_HEADER],
                true
            )
        );
        $cipherOptions['KeySize'] = strlen($cek) * 8;
        $cipherOptions['Cipher'] = $this->getCipherFromAesName(
            $envelope[MetadataEnvelope::CONTENT_CRYPTO_SCHEME_HEADER]
        );

        $decryptionSteam = $this->getDecryptingStream(
            $cipherText,
            $cek,
            $cipherOptions
        );
        unset($cek);

        return $decryptionSteam;
    }
protected function decrypt(
        $cipherText,
        MaterialsProvider $provider,
        MetadataEnvelope $envelope,
        array $cipherOptions = []
    ) {
        $cipherOptions['Iv'] = base64_decode(
            $envelope[MetadataEnvelope::IV_HEADER]
        );

        $cipherOptions['TagLength'] =
            $envelope[MetadataEnvelope::CRYPTO_TAG_LENGTH_HEADER] / 8;

        $cek = $provider->decryptCek(
            base64_decode(
                $envelope[MetadataEnvelope::CONTENT_KEY_V2_HEADER]
            ),
            json_decode(
                $envelope[MetadataEnvelope::MATERIALS_DESCRIPTION_HEADER],
                true
            )
        );
        $cipherOptions['KeySize'] = strlen($cek) * 8;
        $cipherOptions['Cipher'] = $this->getCipherFromAesName(
            $envelope[MetadataEnvelope::CONTENT_CRYPTO_SCHEME_HEADER]
        );

        $decryptionSteam = $this->getDecryptingStream(
            $cipherText,
            $cek,
            $cipherOptions
        );
        unset($cek);

        return $decryptionSteam;
    }
protected function decrypt ( $ cipherText , MaterialsProvider $ provider , MetadataEnvelope $ envelope , array $ cipherOptions = [ ] ) { $ cipherOptions [ 'Iv' ] = base64_decode ( $ envelope [ MetadataEnvelope :: IV_HEADER ] ) ; $ cipherOptions [ 'TagLength' ] = $ envelope [ MetadataEnvelope :: CRYPTO_TAG_LENGTH_HEADER ] / 8 ; $ cek = $ provider -> decryptCek ( base64_decode ( $ envelope [ MetadataEnvelope :: CONTENT_KEY_V2_HEADER ] ) , json_decode ( $ envelope [ MetadataEnvelope :: MATERIALS_DESCRIPTION_HEADER ] , true ) ) ; $ cipherOptions [ 'KeySize' ] = strlen ( $ cek ) * 8 ; $ cipherOptions [ 'Cipher' ] = $ this -> getCipherFromAesName ( $ envelope [ MetadataEnvelope :: CONTENT_CRYPTO_SCHEME_HEADER ] ) ; $ decryptionSteam = $ this -> getDecryptingStream ( $ cipherText , $ cek , $ cipherOptions ) ; unset ( $ cek ) ; return $ decryptionSteam ; }
Builds an AesStreamInterface using cipher options loaded from the
MetadataEnvelope and MaterialsProvider.

@param string $cipherText Plain-text data to be encrypted using the
materials, algorithm, and data provided.
@param MaterialsProvider $provider A provider to supply and encrypt
materials used in encryption.
@param MetadataEnvelope $envelope A storage envelope for encryption
metadata to be read from.
@param array $cipherOptions Additional verification options.

@return AesStreamInterface

@throws \InvalidArgumentException Thrown when a value in $cipherOptions
is not valid.

@internal
Builds an AesStreamInterface using cipher options loaded from the MetadataEnvelope and MaterialsProvider .