Documentation

AesGcm
in package
Uses NeedsTrait

Class AesGcm

This provides a polyfill for AES-GCM encryption/decryption, with caveats:

  1. Only 96-bit nonces are supported.
  2. Only 128-bit authentication tags are supported. (i.e. non-truncated)

Supports AES key sizes of 128-bit, 192-bit, and 256-bit.

Table of Contents

$blockSize  : int
$aesKey  : Key
$keySize  : int
__construct()  : mixed
AesGcm constructor.
decrypt()  : string
Decryption interface for AES-GCM
encrypt()  : string
Encryption interface for AES-GCM
needs()  : mixed
Preconditions, postconditions, and loop invariants are very useful for safe programing. They also document the specifications.
gmacInit()  : array<string|int, mixed>
Initialize a Gmac object with the nonce and this object's key.
strlen()  : int
Calculate the length of a string.
substr()  : string
Return a substring of the provided string.

Properties

$blockSize

protected int $blockSize = 8192

Methods

__construct()

AesGcm constructor.

public __construct(Key $aesKey[, int $keySize = 256 ][, int $blockSize = 8192 ]) : mixed
Parameters
$aesKey : Key
$keySize : int = 256
$blockSize : int = 8192
Tags
throws
CryptoPolyfillException
throws
InvalidArgumentException
throws
RangeException
Return values
mixed —

decrypt()

Decryption interface for AES-GCM

public static decrypt(string $ciphertext, string $nonce, Key $key, string $aad, string &$tag[, int $keySize = 256 ][, int $blockSize = 8192 ]) : string
Parameters
$ciphertext : string

Ciphertext to decrypt

$nonce : string

Number to be used ONCE

$key : Key

AES key

$aad : string

Additional authenticated data

$tag : string

Authentication tag

$keySize : int = 256

Key size (bits)

$blockSize : int = 8192

Block size (bytes) -- How much memory to buffer

Tags
throws
CryptoPolyfillException
throws
InvalidArgumentException
Return values
string —

Plaintext

encrypt()

Encryption interface for AES-GCM

public static encrypt(string $plaintext, string $nonce, Key $key, string $aad, string &$tag[, int $keySize = 256 ][, int $blockSize = 8192 ]) : string
Parameters
$plaintext : string

Message to be encrypted

$nonce : string

Number to be used ONCE

$key : Key

AES Key

$aad : string

Additional authenticated data

$tag : string

Reference to variable to hold tag

$keySize : int = 256

Key size (bits)

$blockSize : int = 8192

Block size (bytes) -- How much memory to buffer

Tags
throws
InvalidArgumentException
Return values
string —

needs()

Preconditions, postconditions, and loop invariants are very useful for safe programing. They also document the specifications.

public static needs( $condition,  $errorMessage[, null $exceptionClass = null ]) : mixed

This function is to help simplify the semantic burden of parsing these constructions.

Instead of constructions like if (!(GOOD CONDITION)) { throw new \Exception('condition not true'); }

you can write: needs(GOOD CONDITION, 'condition not true');

Parameters
$condition :
$errorMessage :
$exceptionClass : null = null
Return values
mixed —

gmacInit()

Initialize a Gmac object with the nonce and this object's key.

protected gmacInit(string $nonce[, string|null $aad = null ]) : array<string|int, mixed>
Parameters
$nonce : string

Must be exactly 12 bytes long.

$aad : string|null = null
Return values
array<string|int, mixed> —

strlen()

Calculate the length of a string.

protected static strlen(string $string) : int

Uses the appropriate PHP function without being brittle to mbstring.func_overload.

Parameters
$string : string
Return values
int —

substr()

Return a substring of the provided string.

protected static substr(string $string, int $offset[, int|null $length = null ]) : string

Uses the appropriate PHP function without being brittle to mbstring.func_overload.

Parameters
$string : string
$offset : int
$length : int|null = null
Return values
string —

Search results