Class \Prado\Security\TSecurityManager
TSecurityManager provides private keys, hashing and encryption functionalities that may be used by other PRADO components, such as viewstate persister, cookies.
TSecurityManager is mainly used to protect data from being tampered and viewed. It can generate HMAC and encrypt the data. The private key used to generate HMAC is set by \Prado\Security\setValidationKey. The key used to encrypt data is specified by \Prado\Security\setEncryptionKey. If the above keys are not explicitly set, random keys will be generated and used.
To prefix data with an HMAC, call hashData(). To validate if data is tampered, call validateData(), which will return the real data if it is not tampered. The algorithm used to generated HMAC is specified by \Prado\Security\setHashAlgorithm.
To encrypt and decrypt data, call encrypt() and decrypt() respectively. The encryption algorithm can be set by \Prado\Security\setCryptAlgorithm.
Note, to use encryption, the PHP OpenSSL extension must be loaded. This was introduced in Prado4, older versions used the deprecated mcrypt extension with rijndael-256 cipher as default, which does not have an equivalent in OpenSSL. Developers should keep that in mind when migrating from Prado3 to Prado4.
Class hierarchy
- \Prado\Security\TSecurityManager
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Author: LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
Since: 3.0
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
init(TXmlElement $config) : mixed
Initializes the module.
The security module is registered with the application. |
public
|
setCryptAlgorithm(mixed $value) : mixed
Sets the crypt algorithm (also known as cipher or cypher) that will be used for {@see encrypt} and {@see decrypt}.
|
public
|
|
public
|
setHashAlgorithm(string $value) : mixed
This method accepts all hash algorithms returned by hash_algos().
|
public
|
|
public
|
|
protected
|
computeHMAC(string $data) : string
Computes the HMAC for the data with {@see getValidationKey ValidationKey}.
|
protected
|
|
private
|
strlen(string $string) : int
Returns the length of the given string.
If available uses the multibyte string function mb_strlen. |
private
|
substr(string $string, int $start, int $length) : string
Returns the portion of string specified by the start and length parameters.
If available uses the multibyte string function mb_substr |
public
mixed
|
STATE_ENCRYPTION_KEY
|
'prado:securitymanager:encryptionkey'
|
public
mixed
|
STATE_VALIDATION_KEY
|
'prado:securitymanager:validationkey'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |