- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml
Classes:
IUserManager
TAuthManager
TAuthorizationRule
TAuthorizationRuleCollection
TDbUser
TDbUserManager
TSecurityManager
TSecurityManagerValidationMode
TUser
TUserManager
TUserManagerPasswordMode

Keyword

# Class TSecurityManager

    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --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.

Since: 3.0
Author: Qiang Xue <qiang.xue@gmail.com>

Method Summary
protected string | computeHMAC ( string $data) Computes the HMAC for the data with getValidationKey.
string | decrypt ( string $data) Decrypts data with getEncryptionKey.
string | encrypt ( string $data) Encrypts data with getEncryptionKey.
protected void | generateRandomKey () Generates a random key.
string | getEncryption ()
string | getEncryptionKey ()
TSecurityManagerValidationMode | getValidation ()
string | getValidationKey ()
string | hashData ( string $data) Prefixes data with an HMAC.
void | init ( TXmlElement $config) Initializes the module.
void | setEncryption ( mixed $value)
void | setEncryptionKey ( string $value)
void | setValidation ( TSecurityManagerValidationMode $value)
void | setValidationKey ( string $value)
string | validateData ( string $data) Validates if data is tampered.

Methods Inherited From TModule
TModule::getID(), TModule::init(), TModule::setID()

Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()

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

Constant Summary
string | STATE_ENCRYPTION_KEY |
string | STATE_VALIDATION_KEY |

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.

Output
Exception

## 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

public TSecurityManagerValidationMode getValidation | ()

Output
TSecurityManagerValidationMode | hashing algorithm used to generate HMAC. Defaults to TSecurityManagerValidationMode::SHA1.
Exception

## 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

public void init | (TXmlElement $config )

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

public void setValidation | (TSecurityManagerValidationMode $value )

Input
TSecurityManagerValidationMode | $value | hashing algorithm used to generate HMAC.
Output
Exception

## 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'