## 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: $Id: TSecurityManager.php 1398 2006-09-08 19:31:03Z xue $
- 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_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 ()
TSecurityManagerValidationMode getValidation ()
string getValidationKey ()
string hashData (string $data)
void init (TXmlElement $config)
void setEncryption (mixed $value)
void setEncryptionKey (string $value)
void setValidation (TSecurityManagerValidationMode $value)
void setValidationKey (string $value)
string validateData (string $data)
Methods
computeHMAC (line 243)

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 189)

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 165)

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 64)

Generates a random key.

- access: protected

void generateRandomKey ()
getEncryption (line 146)

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

string getEncryption ()
getEncryptionKey (line 102)

- 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 130)

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

TSecurityManagerValidationMode getValidation ()
getValidationKey (line 73)

- 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 212)

Prefixes data with an HMAC.

- return: data prefixed with HMAC
- access: public

string hashData (string $data)

- string $data: data to be hashed.

init (line 56)

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 154)

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

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

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

void setEncryptionKey (string $value)

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

setValidation (line 138)

- access: public

void setValidation (TSecurityManagerValidationMode $value)

- TSecurityManagerValidationMode $value: hashing algorithm used to generate HMAC.

setValidationKey (line 90)

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

void setValidationKey (string $value)

- string $value: the key used to generate HMAC

validateData (line 225)

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::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()

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

Documentation generated on Sun, 30 Sep 2007 19:17:18 -0400 by phpDocumentor 1.3.0RC4