## Class TSecurityManager

Description

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.

- since: 3.0
- version: $Revision: $ $Date: $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Security/TSecurityManager.php (line 42)

    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --TSecurityManager

Class Constant Summary
STATE_ENCRYPTION_KEY = 'prado:securitymanager:encryptionkey'
STATE_INIT_VECTOR = 'prado:securitymanager:initvector'
STATE_VALIDATION_KEY = 'prado:securitymanager:validationkey'
Method Summary
string computeHMAC (string $data)
string decrypt (string $data)
string encrypt (string $data)
void generateRandomKey ()
string getEncryption ()
string getEncryptionKey ()
string getValidation ()
string getValidationKey ()
string hashData (string $data)
void init (TXmlElement $config)
void setEncryption (mixed $value)
void setEncryptionKey (string $value)
void setValidation (string $value)
void setValidationKey (string $value)
string validateData (string $data)
Methods
computeHMAC (line 245)

Computes the HMAC for the data with getValidationKey.

- return: the HMAC for the data
- access: protected

string computeHMAC (string $data)

- string $data: data to be generated HMAC

decrypt (line 191)

Decrypts data with getEncryptionKey.

- return: the decrypted data
- access: public
- throws: TNotSupportedException if PHP Mcrypt extension is not loaded

string decrypt (string $data)

- string $data: data to be decrypted.

encrypt (line 167)

Encrypts data with getEncryptionKey.

- return: the encrypted data
- access: public
- throws: TNotSupportedException if PHP Mcrypt extension is not loaded

string encrypt (string $data)

- string $data: data to be encrypted.

generateRandomKey (line 66)

Generates a random key.

- access: protected

void generateRandomKey ()
getEncryption (line 148)

- return: the algorithm used to encrypt/decrypt data. Defaults to '3DES'.
- access: public

string getEncryption ()
getEncryptionKey (line 104)

- return: the private key used to encrypt/decrypt data. If the key is not explicitly set, a random one is generated and returned.
- access: public

string getEncryptionKey ()
getValidation (line 132)

- return: hashing algorithm used to generate HMAC. Defaults to 'SHA1'.
- access: public

string getValidation ()
getValidationKey (line 75)

- return: the private key used to generate HMAC. If the key is not explicitly set, a random one is generated and returned.
- access: public

string getValidationKey ()
hashData (line 214)

Prefixes data with an HMAC.

- return: data prefixed with HMAC
- access: public

string hashData (string $data)

- string $data: data to be hashed.

init (line 58)

Initializes the module.

The security module is registered with the application.

- access: public

void init (TXmlElement $config)

- TXmlElement $config: initial module configuration

Redefinition of:

TModule::init()
  Initializes the module.

setEncryption (line 156)

- access: public
- throws: TNotSupportedException Do not call this method presently.

void setEncryption (mixed $value)
setEncryptionKey (line 121)

- access: public
- throws: TInvalidDataValueException if the key is empty

void setEncryptionKey (string $value)

- string $value: the key used to encrypt/decrypt data.

setValidation (line 140)

- access: public

void setValidation (string $value)

- string $value: hashing algorithm used to generate HMAC. Valid values include 'SHA1' and 'MD5'.

setValidationKey (line 92)

- access: public
- throws: TInvalidDataValueException if the key is empty

void setValidationKey (string $value)

- string $value: the key used to generate HMAC

validateData (line 227)

Validates if data is tampered.

- return: the real data with HMAC stripped off. False if the data is tampered.
- access: public

string validateData (string $data)

- string $data: data to be validated. The data must be previously generated using hashData().

#### Inherited Methods

Inherited From TModule

> TModule::getID()
> TModule::init()
> TModule::setID()

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

Inherited From TComponent

> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Class Constants
STATE_ENCRYPTION_KEY = 'prado:securitymanager:encryptionkey' (line 45)
STATE_INIT_VECTOR = 'prado:securitymanager:initvector' (line 46)
STATE_VALIDATION_KEY = 'prado:securitymanager:validationkey' (line 44)

Documentation generated on Sun, 04 Jun 2006 19:00:17 -0400 by phpDocumentor 1.3.0RC4