PHP Class Phalcon\Legacy\Crypt

Port of Phalcon 2.0.x Phalcon\Crypt. Provides encryption facilities to phalcon applications. $crypt = new \Phalcon\Legacy\Crypt(); $key = 'le password'; $text = 'This is a secret text'; $encrypted = $crypt->encrypt($text, $key); echo $crypt->decrypt($encrypted, $key);
Inheritance: implements Phalcon\Legacy\CryptInterface
Show file Open project: phalcon/incubator Class Usage Examples

Protected Properties

Property Type Description
$cipher
$key
$mode
$padding

Public Methods

Method Description
decrypt ( string $text, string $key = null ) : string Decrypts a text
decryptBase64 ( string $text, mixed $key = null, boolean $safe = false ) : string Decrypt a text that is coded as a base64 string
encrypt ( string $text, mixed $key = null ) : string Encrypts a text
encryptBase64 ( string $text, mixed $key = null, boolean $safe = false ) : string Encrypts a text returning the result as a base64 string
getAvailableCiphers ( ) : array Returns a list of available cyphers
getAvailableModes ( ) : array Returns a list of available modes
getCipher ( ) : string Returns the current cipher
getKey ( ) : string Returns the encryption key
getMode ( ) : string Returns the current encryption mode
setCipher ( string $cipher ) : Phalcon\Legacy\CryptInterface
setKey ( string $key ) : Phalcon\Legacy\CryptInterface Sets the encryption key
setMode ( string $mode ) : Phalcon\Legacy\CryptInterface Sets the encrypt/decrypt mode
setPadding ( integer $scheme ) : Phalcon\Legacy\CryptInterface Changes the padding scheme used

Protected Methods

Method Description
cryptPadText ( string $text, string $mode, integer $blockSize, integer $paddingType ) : string Pads texts before encryption
cryptUnpadText ( string $text, string $mode, integer $blockSize, integer $paddingType ) : string Removes $paddingType padding from text If the function detects that the text was not padded, it will return it unmodified

Method Details

cryptPadText() protected method

Pads texts before encryption
protected cryptPadText ( string $text, string $mode, integer $blockSize, integer $paddingType ) : string
$text string
$mode string
$blockSize integer
$paddingType integer
return string

cryptUnpadText() protected method

Removes $paddingType padding from text If the function detects that the text was not padded, it will return it unmodified
protected cryptUnpadText ( string $text, string $mode, integer $blockSize, integer $paddingType ) : string
$text string Message to be unpadded
$mode string Encryption mode; unpadding is applied only in CBC or ECB mode
$blockSize integer Cipher block size
$paddingType integer Padding scheme
return string

decrypt() public method

echo $crypt->decrypt($encrypted, "decrypt password");
public decrypt ( string $text, string $key = null ) : string
$text string
$key string
return string

decryptBase64() public method

Decrypt a text that is coded as a base64 string
public decryptBase64 ( string $text, mixed $key = null, boolean $safe = false ) : string
$text string
$key mixed
$safe boolean
return string

encrypt() public method

$encrypted = $crypt->encrypt("Ultra-secret text", "encrypt password");
public encrypt ( string $text, mixed $key = null ) : string
$text string
$key mixed
return string

encryptBase64() public method

Encrypts a text returning the result as a base64 string
public encryptBase64 ( string $text, mixed $key = null, boolean $safe = false ) : string
$text string
$key mixed
$safe boolean
return string

getAvailableCiphers() public method

Returns a list of available cyphers
public getAvailableCiphers ( ) : array
return array

getAvailableModes() public method

Returns a list of available modes
public getAvailableModes ( ) : array
return array

getCipher() public method

Returns the current cipher
public getCipher ( ) : string
return string

getKey() public method

Returns the encryption key
public getKey ( ) : string
return string

getMode() public method

Returns the current encryption mode
public getMode ( ) : string
return string

setCipher() public method

public setCipher ( string $cipher ) : Phalcon\Legacy\CryptInterface
$cipher string
return Phalcon\Legacy\CryptInterface

setKey() public method

Sets the encryption key
public setKey ( string $key ) : Phalcon\Legacy\CryptInterface
$key string
return Phalcon\Legacy\CryptInterface

setMode() public method

Sets the encrypt/decrypt mode
public setMode ( string $mode ) : Phalcon\Legacy\CryptInterface
$mode string
return Phalcon\Legacy\CryptInterface

setPadding() public method

Changes the padding scheme used
public setPadding ( integer $scheme ) : Phalcon\Legacy\CryptInterface
$scheme integer
return Phalcon\Legacy\CryptInterface

Property Details

$cipher protected property

protected $cipher

$key protected property

protected $key

$mode protected property

protected $mode

$padding protected property

protected $padding