AesGcm
in package
Uses
NeedsTrait
Class AesGcm
This provides a polyfill for AES-GCM encryption/decryption, with caveats:
- Only 96-bit nonces are supported.
- 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
Methods
- __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.
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
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
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
Return values
stringneeds()
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');