Jose\Algorithm\ContentEncryptionAlgorithmInterface::encryptContent PHP Method

encryptContent() public method

Encrypt data.
public encryptContent ( string $data, string $cek, string $iv, string | null $aad, string $encoded_protected_header, string &$tag ) : string
$data string The data to encrypt
$cek string The content encryption key
$iv string The Initialization Vector
$aad string | null Additional Additional Authenticated Data
$encoded_protected_header string The Protected Header encoded in Base64Url
$tag string Tag
return string The encrypted data
    public function encryptContent($data, $cek, $iv, $aad, $encoded_protected_header, &$tag);

Usage Example

Example #1
0
 /**
  * @param \Jose\Object\JWEInterface                           $jwe
  * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm
  * @param string                                              $cek
  * @param string                                              $iv
  * @param \Jose\Compression\CompressionInterface|null         $compression_method
  */
 private function encryptJWE(Object\JWEInterface &$jwe, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, $cek, $iv, Compression\CompressionInterface $compression_method = null)
 {
     if (!empty($jwe->getSharedProtectedHeaders())) {
         $jwe = $jwe->withEncodedSharedProtectedHeaders(Base64Url::encode(json_encode($jwe->getSharedProtectedHeaders())));
     }
     $tag = null;
     $payload = $this->preparePayload($jwe->getPayload(), $compression_method);
     $aad = null === $jwe->getAAD() ? null : Base64Url::encode($jwe->getAAD());
     $ciphertext = $content_encryption_algorithm->encryptContent($payload, $cek, $iv, $aad, $jwe->getEncodedSharedProtectedHeaders(), $tag);
     $jwe = $jwe->withCiphertext($ciphertext);
     $jwe = $jwe->withIV($iv);
     if (null !== $tag) {
         $jwe = $jwe->withTag($tag);
     }
 }