PHP Класс 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 {@link setValidationKey ValidationKey}. The key used to encrypt data is specified by {@link setEncryptionKey EncryptionKey}. If the above keys are not explicitly set, random keys will be generated and used. To prefix data with an HMAC, call {@link hashData()}. To validate if data is tampered, call {@link validateData()}, which will return the real data if it is not tampered. The algorithm used to generated HMAC is specified by {@link setValidation Validation}. To encrypt and decrypt data, call {@link encrypt()} and {@link decrypt()} respectively. The encryption algorithm can be set by {@link setEncryption Encryption}. Note, to use encryption, the PHP Mcrypt extension must be loaded.
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\TModule
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
decrypt ( $data ) : string Decrypts data with {@link getEncryptionKey EncryptionKey}.
encrypt ( $data ) : string Encrypts data with {@link getEncryptionKey EncryptionKey}.
getCryptAlgorithm ( ) : mixed
getEncryption ( ) : string This method has been deprecated since version 3.2.1.
getEncryptionKey ( ) : string
getHashAlgorithm ( ) : string
getValidation ( ) : string This method has been deprecated since version 3.2.1.
getValidationKey ( ) : string
hashData ( $data ) : string Prefixes data with an HMAC.
init ( $config ) Initializes the module.
setCryptAlgorithm ( $value ) Sets the crypt algorithm (also known as cipher or cypher) that will be used for {@link encrypt} and {@link decrypt}.
setEncryption ( $value ) This method has been deprecated since version 3.2.1.
setEncryptionKey ( $value )
setHashAlgorithm ( $value )
setValidation ( $value ) This method has been deprecated since version 3.2.1.
setValidationKey ( $value )
validateData ( $data ) : string Validates if data is tampered.

Защищенные методы

Метод Описание
computeHMAC ( $data ) : string Computes the HMAC for the data with {@link getValidationKey ValidationKey}.
generateRandomKey ( ) Generates a random key.
openCryptModule ( ) : resource Opens the mcrypt module with the configuration specified in {@link cryptAlgorithm}.

Приватные методы

Метод Описание
strlen ( string $string ) : integer Returns the length of the given string.
substr ( string $string, integer $start, integer $length ) : string Returns the portion of string specified by the start and length parameters.

Описание методов

computeHMAC() защищенный Метод

Computes the HMAC for the data with {@link getValidationKey ValidationKey}.
protected computeHMAC ( $data ) : string
Результат string the HMAC for the data

decrypt() публичный Метод

Decrypts data with {@link getEncryptionKey EncryptionKey}.
public decrypt ( $data ) : string
Результат string the decrypted data

encrypt() публичный Метод

Encrypts data with {@link getEncryptionKey EncryptionKey}.
public encrypt ( $data ) : string
Результат string the encrypted data

generateRandomKey() защищенный Метод

Generates a random key.
protected generateRandomKey ( )

getCryptAlgorithm() публичный Метод

public getCryptAlgorithm ( ) : mixed
Результат mixed the algorithm used to encrypt/decrypt data. Defaults to the string 'rijndael-256'.

getEncryption() публичный Метод

Please use {@link getCryptAlgorithm()} instead.
public getEncryption ( ) : string
Результат string the algorithm used to encrypt/decrypt data.

getEncryptionKey() публичный Метод

public getEncryptionKey ( ) : string
Результат string the private key used to encrypt/decrypt data. If the key is not explicitly set, a random one is generated and returned.

getHashAlgorithm() публичный Метод

public getHashAlgorithm ( ) : string
Результат string hashing algorithm used to generate HMAC. Defaults to 'sha1'.

getValidation() публичный Метод

Please use {@link getHashAlgorithm()} instead.
public getValidation ( ) : string
Результат string hashing algorithm used to generate HMAC. Defaults to 'sha1'.

getValidationKey() публичный Метод

public getValidationKey ( ) : string
Результат string the private key used to generate HMAC. If the key is not explicitly set, a random one is generated and returned.

hashData() публичный Метод

Prefixes data with an HMAC.
public hashData ( $data ) : string
Результат string data prefixed with HMAC

init() публичный Метод

The security module is registered with the application.
public init ( $config )

openCryptModule() защищенный Метод

Opens the mcrypt module with the configuration specified in {@link cryptAlgorithm}.
С версии: 3.2.1
protected openCryptModule ( ) : resource
Результат resource the mycrypt module handle.

setCryptAlgorithm() публичный Метод

Sets the crypt algorithm (also known as cipher or cypher) that will be used for {@link encrypt} and {@link decrypt}.
public setCryptAlgorithm ( $value )

setEncryption() публичный Метод

Please use {@link setCryptAlgorithm()} instead.
public setEncryption ( $value )

setEncryptionKey() публичный Метод

public setEncryptionKey ( $value )

setHashAlgorithm() публичный Метод

public setHashAlgorithm ( $value )

setValidation() публичный Метод

Please use {@link setHashAlgorithm()} instead.
public setValidation ( $value )

setValidationKey() публичный Метод

public setValidationKey ( $value )

validateData() публичный Метод

Validates if data is tampered.
public validateData ( $data ) : string
Результат string the real data with HMAC stripped off. False if the data is tampered.