Luminova Framework

PHP Luminova: Encryption Interface Class

Last updated: 2024-04-01 22:52:09

A Comprehensive Guide to the luminova's Encryption Interface Class for PHP Framework Integration with OpenSSL and Sodium Libraries.

The Luminova Crypter class serves as a valuable asset for developers utilizing the Luminova PHP framework, offering a convenient and secure solution for implementing encryption and decryption functionalities. By abstracting away the complexities of cryptographic libraries and providing a unified interface, the Crypter class facilitates the integration of encryption features into PHP applications, enhancing overall security and reliability.

  • Class namespace: \Luminova\Interface\EncryptionInterface

Methods

constructor

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

public __construct(string $key = ''): mixed

Parameters:

ParameterTypeDescription
$keystringThe encryption key.

Throws:


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.

setCypherAlgo

Set the encryption method and block size for openssl.

public setCypherAlgo(int|null $blockSize, string $mode): void

Parameters:

ParameterTypeDescription
$blockSizeint|nullThe block size for encryption.
$modestringThe encryption mode.

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:

string - The nonce string.


encrypt

Encrypt data.

public encrypt(): string|bool

Return Value:

string|bool - The encrypted data, or false if encryption fails.

Throws:


decrypt

Decrypt data.

public decrypt(): string|bool

Return Value:

string|bool - The decrypted data, or false if decryption fails.

Throws:


free

Free up resources.

public free(): void