Class TSecurityManager
TSecurityManager class
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 ValidationKey. The key used to encrypt data is specified by EncryptionKey. 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 Validation. To encrypt and decrypt data, call encrypt() and decrypt() respectively. The encryption algorithm can be set by Encryption. Note, to use encryption, the PHP Mcrypt extension must be loaded.
Method Summary |
protected
string
|
Computes the HMAC for the data with getValidationKey.
|
string
|
Decrypts data with getEncryptionKey.
|
string
|
Encrypts data with getEncryptionKey.
|
protected
void
|
Generates a random key.
|
string
|
|
string
|
|
TSecurityManagerValidationMode
|
|
string
|
|
string
|
Prefixes data with an HMAC.
|
void
|
Initializes the module.
|
void
|
|
void
|
|
void
|
|
void
|
|
string
|
Validates if data is tampered.
|
Methods Inherited From TComponent |
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
Method Details |
computeHMAC
protected string computeHMAC |
(string $data ) |
Computes the HMAC for the data with getValidationKey.
Input |
string | $data | data to be generated HMAC |
Output |
string
| the HMAC for the data |
Exception |
|
decrypt
public string decrypt |
(string $data ) |
Decrypts data with getEncryptionKey.
Input |
string | $data | data to be decrypted. |
Output |
string
| the decrypted data |
Exception |
throws | TNotSupportedException if PHP Mcrypt extension is not loaded |
|
encrypt
public string encrypt |
(string $data ) |
Encrypts data with getEncryptionKey.
Input |
string | $data | data to be encrypted. |
Output |
string
| the encrypted data |
Exception |
throws | TNotSupportedException if PHP Mcrypt extension is not loaded |
|
generateRandomKey
protected void generateRandomKey |
() |
Generates a random key.
|
getEncryption
public string getEncryption |
() |
Output |
string
| the algorithm used to encrypt/decrypt data. Defaults to '3DES'. |
Exception |
|
getEncryptionKey
public string getEncryptionKey |
() |
Output |
string
| the private key used to encrypt/decrypt data. If the key is not explicitly set, a random one is generated and returned. |
Exception |
|
getValidation
|
getValidationKey
public string getValidationKey |
() |
Output |
string
| the private key used to generate HMAC. If the key is not explicitly set, a random one is generated and returned. |
Exception |
|
hashData
public string hashData |
(string $data ) |
Prefixes data with an HMAC.
Input |
string | $data | data to be hashed. |
Output |
string
| data prefixed with HMAC |
Exception |
|
init
Initializes the module.
The security module is registered with the application.
Input |
TXmlElement | $config | initial module configuration |
Output |
Exception |
|
setEncryption
public void setEncryption |
(mixed $value ) |
Input |
mixed | $value | |
Output |
Exception |
throws | TNotSupportedException Do not call this method presently. |
|
setEncryptionKey
public void setEncryptionKey |
(string $value ) |
Input |
string | $value | the key used to encrypt/decrypt data. |
Output |
Exception |
throws | TInvalidDataValueException if the key is empty |
|
setValidation
|
setValidationKey
public void setValidationKey |
(string $value ) |
Input |
string | $value | the key used to generate HMAC |
Output |
Exception |
throws | TInvalidDataValueException if the key is empty |
|
validateData
public string validateData |
(string $data ) |
Validates if data is tampered.
Input |
string | $data | data to be validated. The data must be previously generated using hashData(). |
Output |
string
| the real data with HMAC stripped off. False if the data is tampered. |
Exception |
|
Constant Details |
STATE_ENCRYPTION_KEY
Type:
string
Value:
'prado:securitymanager:encryptionkey'
|
STATE_VALIDATION_KEY
Type:
string
Value:
'prado:securitymanager:validationkey'
|
|