Luminova Framework

Encryption Driver

Last updated: 2024-04-19 00:46:22

The Encryption Driver provides a flexible solution for data encryption within the Luminova Framework. It serves as an abstraction layer that supports multiple encryption algorithms, including OpenSSL and Sodium, ensuring robust security measures while offering developers the flexibility to choose the encryption method that best fits their needs.


  • Class interface: \Luminova\Interface\EncryptionInterface

constructor

Constructor, optional pass a blank key string and setKey() later before encrypt/decrypt.

OpenSSL Class namespace: \Luminova\Security\Encryption\OpenSSL

new OpenSSL(?string $key = null, ?string $method = null, int $size = 16);

Sodium Class namespace: \Luminova\Security\Encryption\Sodium

new Sodium(?string $key = null, ?string $method = null, int $size = 16);

Parameters:

ParameterTypeDescription
$keystring|nullThe encryption key.
$methodstring|nullOptional encryption cypher method..
$sizeintOptional key size for encryption..

Throws:


Methods


setData

Set the data to encrypt/decrypt.

public setData(string $data): void

Parameters:

ParameterTypeDescription
$datastringThe data to encrypt/decrypt.

setKey

Set the encryption key.

public setKey(string $key): void

Parameters:

ParameterTypeDescription
$keystringThe encryption key.

setNonce

Set nonce for encryption and decryption, if null random nonce will be generated.

public setNonce(string|null $nonce = null): void

Parameters:

ParameterTypeDescription
$noncestring|nullThe nonce for encryption.

setMethod

Set the encryption method and block size for openssl, this method will be ignored on Sodium.

public setMethod(string $method, int $size = 16): void

Parameters:

ParameterTypeDescription
$methodstringThe encryption cypher method.
$modeintOptional Key size for encryption..

Throws:


nonce

Generate a random nonce, or return from a string.

public nonce(string|null $string = null): string

Parameters:

ParameterTypeDescription
$stringstring|nullThe string to extract the nonce from.

Return Value:

The nonce string.


encrypt

Encrypt data.

public encrypt(): string|bool

Return Value:

The encrypted data, or false if encryption fails.

Throws:


decrypt

Decrypt data.

public decrypt(): string|bool

Return Value:

The decrypted data, or false if decryption fails.

Throws:


free

Free up resources.

public free(): void