- md5
- 212efd390b42bd947cd128257ec48a9b
- sha1
- ae7706998aa2853217aecb62a93c367d34a69e94
- sha256
- 0c7bae171f8f2b3bb55f0d96ec6f8963567f0a14785323910e983058febb17ef
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
<?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.