CoreFiles by mySites.guru
AESCCM.php72 lines, 1,805 bytes, from Joomla_5.1.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.0.0-beta3
md5
212efd390b42bd947cd128257ec48a9b
sha1
ae7706998aa2853217aecb62a93c367d34a69e94
sha256
0c7bae171f8f2b3bb55f0d96ec6f8963567f0a14785323910e983058febb17ef
<?php

declare(strict_types=1);

namespace Jose\Experimental\ContentEncryption;

use Jose\Component\Encryption\Algorithm\ContentEncryptionAlgorithm;
use RuntimeException;
use const OPENSSL_RAW_DATA;

abstract class AESCCM implements ContentEncryptionAlgorithm
{
    public function allowedKeyTypes(): array
    {
        return []; //Irrelevant
    }

    public function encryptContent(
        string $data,
        string $cek,
        string $iv,
        ?string $aad,
        string $encoded_protected_header,
        ?string &$tag = null
    ): string {
        $calculated_aad = $encoded_protected_header;
        if ($aad !== null) {
            $calculated_aad .= '.' . $aad;
        }
        $tag = '';
        $result = openssl_encrypt(
            $data,
            $this->getMode(),
            $cek,
            OPENSSL_RAW_DATA,
            $iv,
            $tag,
            $calculated_aad,
            $this->getTagLength()
        );
        if ($result === false) {
            throw new RuntimeException('Unable to encrypt the content');
        }

        return $result;
    }

    public function decryptContent(
        string $data,
        string $cek,
        string $iv,
        ?string $aad,
        string $encoded_protected_header,
        string $tag
    ): string {
        $calculated_aad = $encoded_protected_header;
        if ($aad !== null) {
            $calculated_aad .= '.' . $aad;
        }

        $result = openssl_decrypt($data, $this->getMode(), $cek, OPENSSL_RAW_DATA, $iv, $tag, $calculated_aad);
        if ($result === false) {
            throw new RuntimeException('Unable to decrypt the content');
        }

        return $result;
    }

    abstract protected function getMode(): string;

    abstract protected function getTagLength(): int;
}

No other release has this exact content. See every version of this file.