Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
Encryption Class Reference

Ubiquity\security\data$Encryption This class is part of Ubiquity Inspired from illuminate/encryption package. More...

Public Member Functions

 __construct (?string $key=null, ?string $cipher=null)
 Create a new encrypter instance.
 
 initializeKeyAndCipher ()
 
 encrypt ($value, $serialize=true)
 Encrypt the given value.
 
 encryptString (string $value)
 Encrypt a string without serialization.
 
 decrypt (string $payload, $unserialize=true)
 Decrypt the given value.
 
 decryptString ($payload)
 Decrypt the given string without unserialization.
 
 getKey ()
 
 getCipher ()
 

Static Public Member Functions

static getCipherFromKey (string $key)
 
static isValidKey (string $key, string $cipher)
 Check if the given key and cipher combination is valid.
 
static generateKey (string $cipher)
 Generate a new key for the given cipher.
 
static getMethods (?bool $aliases=null)
 

Data Fields

const AES128 = 'AES-128-CBC'
 
const AES192 = 'AES-192-CBC'
 
const AES256 = 'AES-256-CBC'
 

Protected Member Functions

 hash ($iv, $value)
 Create a MAC for the given value.
 
 getJsonPayload ($payload)
 Get the JSON array from the given payload.
 
 isValidPayload ($payload)
 Check that the encryption payload is valid.
 
 isValidMac (array $payload)
 Check if the MAC for the given payload is valid.
 
 calculateMac ($payload, $bytes)
 Calculate the hash of the given payload.
 

Protected Attributes

 $key
 
 $cipher
 

Static Private Attributes

static $acceptedCiphers
 

Detailed Description

Ubiquity\security\data$Encryption This class is part of Ubiquity Inspired from illuminate/encryption package.

Author
jc
Version
1.0.0

Definition at line 18 of file Encryption.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ?string  $key = null,
?string  $cipher = null 
)

Create a new encrypter instance.

Parameters
string$key
string$cipher
Returns
void
Exceptions

RuntimeException

Definition at line 55 of file Encryption.php.

Member Function Documentation

◆ calculateMac()

calculateMac (   $payload,
  $bytes 
)
protected

Calculate the hash of the given payload.

Parameters
array$payload
string$bytes
Returns
string

Definition at line 137 of file Encryption.php.

◆ decrypt()

decrypt ( string  $payload,
  $unserialize = true 
)

Decrypt the given value.

Parameters
string$payload
bool$unserialize
Returns
mixed

Definition at line 183 of file Encryption.php.

◆ decryptString()

decryptString (   $payload)

Decrypt the given string without unserialization.

Parameters
string$payload
Returns
string

Definition at line 202 of file Encryption.php.

◆ encrypt()

encrypt (   $value,
  $serialize = true 
)

Encrypt the given value.

Parameters
mixed$value
bool$serialize
Returns
string

Definition at line 149 of file Encryption.php.

◆ encryptString()

encryptString ( string  $value)

Encrypt a string without serialization.

Parameters
string$value
Returns
string

Definition at line 171 of file Encryption.php.

◆ generateKey()

static generateKey ( string  $cipher)
static

Generate a new key for the given cipher.

Parameters
string$cipher
Returns
string

Definition at line 224 of file Encryption.php.

◆ getCipher()

getCipher ( )
Returns
string

Definition at line 241 of file Encryption.php.

◆ getCipherFromKey()

static getCipherFromKey ( string  $key)
static

Definition at line 72 of file Encryption.php.

◆ getJsonPayload()

getJsonPayload (   $payload)
protected

Get the JSON array from the given payload.

Parameters
string$payload
Returns
array

Definition at line 97 of file Encryption.php.

◆ getKey()

getKey ( )
Returns
string

Definition at line 233 of file Encryption.php.

◆ getMethods()

static getMethods ( ?bool  $aliases = null)
static

Definition at line 245 of file Encryption.php.

◆ hash()

hash (   $iv,
  $value 
)
protected

Create a MAC for the given value.

Parameters
string$iv
mixed$value
Returns
string

Definition at line 87 of file Encryption.php.

◆ initializeKeyAndCipher()

initializeKeyAndCipher ( )

Definition at line 60 of file Encryption.php.

◆ isValidKey()

static isValidKey ( string  $key,
string  $cipher 
)
static

Check if the given key and cipher combination is valid.

Parameters
string$key
string$cipher
Returns
bool

Definition at line 213 of file Encryption.php.

◆ isValidMac()

isValidMac ( array  $payload)
protected

Check if the MAC for the given payload is valid.

Parameters
array$payload
Returns
bool

Definition at line 125 of file Encryption.php.

◆ isValidPayload()

isValidPayload (   $payload)
protected

Check that the encryption payload is valid.

Parameters
mixed$payload
Returns
bool

Definition at line 115 of file Encryption.php.

Field Documentation

◆ $acceptedCiphers

$acceptedCiphers
staticprivate

◆ $cipher

$cipher
protected

Definition at line 44 of file Encryption.php.

◆ $key

$key
protected

Definition at line 37 of file Encryption.php.

◆ AES128

const AES128 = 'AES-128-CBC'

Definition at line 20 of file Encryption.php.

◆ AES192

const AES192 = 'AES-192-CBC'

Definition at line 22 of file Encryption.php.

◆ AES256

const AES256 = 'AES-256-CBC'

Definition at line 24 of file Encryption.php.


The documentation for this class was generated from the following file: