class Utils (View source)

Utility helper for cryptography and UUID manipulation.

This class provides secure AES-256-GCM encryption/decryption, UUID format conversion, and key retrieval from configuration.

Constants

private ENCRYPTION_VERSION

Current encryption version tag used in the payload.

Helps maintain compatibility if algorithms change in the future.

private CIPHER_METHOD

Cipher algorithm and IV length constants.

private IV_LENGTH

private TAG_LENGTH

Methods

static string
encrypt(string $plainText)

Encrypts a string using AES-256-GCM with a random IV and version tag.

static string
decrypt(string $encryptedData)

Decrypts data previously encrypted using AES-256-GCM.

static string|null
convertUuidToBinary(string $uuid)

Converts a UUID (hex string, with or without hyphens) to binary format.

static string
convertBinaryToUuid(string $binary)

Converts a binary UUID to a string representation.

Details

static string encrypt(string $plainText)

Encrypts a string using AES-256-GCM with a random IV and version tag.

Parameters

string $plainText

the plain text to be encrypted

Return Value

string

binary output: VERSION + IV + TAG + ENCRYPTED_DATA

Exceptions

RuntimeException

static string decrypt(string $encryptedData)

Decrypts data previously encrypted using AES-256-GCM.

Parameters

string $encryptedData

binary input: VERSION + IV + TAG + ENCRYPTED_DATA

Return Value

string

the decrypted plain text

Exceptions

RuntimeException

static string|null convertUuidToBinary(string $uuid)

Converts a UUID (hex string, with or without hyphens) to binary format.

Parameters

string $uuid

UUID string (e.g., "123e4567-e89b-12d3-a456-426614174000").

Return Value

string|null

binary UUID or null if invalid

Exceptions

InvalidArgumentException

static string convertBinaryToUuid(string $binary)

Converts a binary UUID to a string representation.

Parameters

string $binary

binary UUID (16 bytes)

Return Value

string

UUID string (e.g., "123e4567-e89b-12d3-a456-426614174000").

Exceptions

InvalidArgumentException