FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Encrypt Class Reference

Encryption (and decryption) component. More...

Inheritance diagram for Encrypt:
Component Thing

Public Member Functions

 str ($str, $key=null)
 Encrypt a string. More...
 
 decrypt ($data, $key=null)
 Decrypt an encrypted string. More...
 
 file ($source, $target, $key=null)
 Encrypt a file. More...
 
 decryptFile ($source, $target, $key=null)
 Decrypt an encrypted file. More...
 
- Public Member Functions inherited from Component
 __construct ($fred, $config=null)
 
 __destruct ()
 
 clientConfig ()
 Public configuration. More...
 
 config ($key, $default=null)
 Retrieve a config value. More...
 
 ping ()
 Ping function. More...
 
 filemtime ($filename)
 Filemtime with session cache. More...
 
 component ($name)
 Get a component (local or default). More...
 
 components (... $names)
 Get multiple components in an array. More...
 
- Public Member Functions inherited from Thing
 propertyExists ($property)
 Check if a property exists (public or published). More...
 
 constants ($prefix=null)
 Return all constants. More...
 
 get ($key)
 Get one or more properties. More...
 
 set ($key, $value=null)
 Set one or more properties. More...
 
 __get ($key)
 
 __set ($key, $value)
 

Protected Member Functions

 key ($key)
 Generate an encryption key. More...
 
 initVector (&$length=null)
 Generate an initialization vector. More...
 
 getKey ()
 
- Protected Member Functions inherited from Component
 init ()
 
 done ()
 
 getSession ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). More...
 
 configure ($config)
 Configure the object. More...
 
 _get ($key)
 Default getter if no specific setter is defined, and the property is also not published (readable). More...
 
 _set ($key, $value)
 Default setter if no specific setter is defined, and the property is also not published (writeable). More...
 

Protected Attributes

 $_key = null
 Master key (used for padding). More...
 
 $_keyFile = null
 File where master key is stored. If the file does not exist, a key is generated and saved. More...
 
 $_method = 'AES-256-CTR'
 Encryption method (see openssl_get_cipher_methods()). More...
 
 $_blockSize = 32000
 File encryption block size. More...
 
- Protected Attributes inherited from Component
 $_fred = null
 
 $_config = null
 
 $_name = null
 
 $_components = []
 Local components (key = component name, value = component). More...
 
 $_session = null
 
- Protected Attributes inherited from Thing
 $_published = []
 Published properties (key = name of property, value = visibility). More...
 

Additional Inherited Members

- Data Fields inherited from Component
 $filemtimeTtl = 0
 
- Data Fields inherited from Thing
const HIDDEN = 0
 Property is hidden. More...
 
const READABLE = 1
 Property is readable. More...
 
const WRITEABLE = 2
 Property is writeable. More...
 
const READWRITE = 3
 Property is readable and writeable. More...
 

Detailed Description

Encryption (and decryption) component.

Definition at line 8 of file Encrypt.php.

Member Function Documentation

◆ decrypt()

decrypt (   $data,
  $key = null 
)

Decrypt an encrypted string.

Parameters
string$dataString encrypted with str().
string$keyKey for decryption (same one as used with encryption).
Returns
string Decrypted string.

Definition at line 49 of file Encrypt.php.

◆ decryptFile()

decryptFile (   $source,
  $target,
  $key = null 
)

Decrypt an encrypted file.

Parameters
string$sourceFile encrypted with file().
string$targetFile to write decrypted data to.
string$keyKey for decryption (same one as used with encryption).
Returns
int Number of bytes written.

Definition at line 82 of file Encrypt.php.

◆ file()

file (   $source,
  $target,
  $key = null 
)

Encrypt a file.

Parameters
string$sourceOriginal file.
string$targetFile to write encrypted data to. This includes the used method and block size, so these can be safely changed.
string$keyKey for encryption.
Returns
int Number of bytes written.

Definition at line 61 of file Encrypt.php.

◆ getKey()

getKey ( )
protected

Definition at line 98 of file Encrypt.php.

◆ initVector()

initVector ( $length = null)
protected

Generate an initialization vector.

Parameters
int$lengthLength of the initialization vector.
Returns
string Generated initialization vector (binary).

Definition at line 28 of file Encrypt.php.

◆ key()

key (   $key)
protected

Generate an encryption key.

Parameters
string$keyCustom/user key.
Returns
string Generated key based on custom/user key and master key (binary).

Definition at line 20 of file Encrypt.php.

◆ str()

str (   $str,
  $key = null 
)

Encrypt a string.

Parameters
string$strInput string.
string$keyKey for encryption.
Returns
string Encrypted data (binary). This includes the used method, so this can be safely changed.

Definition at line 39 of file Encrypt.php.

Field Documentation

◆ $_blockSize

$_blockSize = 32000
protected

File encryption block size.

Definition at line 13 of file Encrypt.php.

◆ $_key

$_key = null
protected

Master key (used for padding).

Definition at line 10 of file Encrypt.php.

◆ $_keyFile

$_keyFile = null
protected

File where master key is stored. If the file does not exist, a key is generated and saved.

Definition at line 11 of file Encrypt.php.

◆ $_method

$_method = 'AES-256-CTR'
protected

Encryption method (see openssl_get_cipher_methods()).

Definition at line 12 of file Encrypt.php.


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