PHP Класс Webiny\Component\Crypt\Crypt

Наследование: use trait Webiny\Component\StdLib\ComponentTrait, use trait Webiny\Component\StdLib\StdLibTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$cipher string * @var string Mcrypt cipher used for encryption and decryption.
$cipherMode Mcrypt mode used for encryption and decryption.
$passwordAlgo Password algorithm used by password_hash

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

Метод Описание
__construct ( ) Base constructor.
createPasswordHash ( string $password ) : string Creates a hash from the given $password string.
decrypt ( string $string, string $key ) : string Decrypt a string that has been encrypted with the 'encrypt' method.
encrypt ( string $string, string $key ) : string Encrypt the given $string using a cypher and the secret $key
generateHardReadableString ( integer $length ) : string Generates a random string with a lot of 'noise' (special characters).
generateRandomInt ( integer $min, integer $max ) : integer Generates a random integer between the given $min and $max values.
generateRandomString ( integer $length, string $chars = '' ) : string Generates a random string using the defined character set.
generateUserReadableString ( integer $length ) : string Generates a random string, but without using special characters that are hard to read.
verifyPasswordHash ( string $password, string $hash ) : boolean Verify if the given $hash matches the given $password.

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

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

Base constructor.
public __construct ( )

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

The hashing algorithm used depends on your config.
public createPasswordHash ( string $password ) : string
$password string String you wish to hash.
Результат string Hash of the given string.

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

In order to decrypt the string correctly, you must provide the same secret key that was used for the encryption process.
public decrypt ( string $string, string $key ) : string
$string string The string you want to decrypt.
$key string The secret key that was used to encrypt the $string.
Результат string Decrypted string or false if unable to decrypt (wrong key).

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

Encrypt the given $string using a cypher and the secret $key
public encrypt ( string $string, string $key ) : string
$string string The string you want to encrypt.
$key string The secret key that will be used to encrypt the string.
Результат string Encrypted string.

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

Use this method to generate API keys, salts and similar.
public generateHardReadableString ( integer $length ) : string
$length integer Length of the random string.
Результат string Random string with the given $length.

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

Generates a random integer between the given $min and $max values.
public generateRandomInt ( integer $min, integer $max ) : integer
$min integer Lower limit.
$max integer Upper limit
Результат integer Random number between $min and $max.

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

If $chars param is empty, the string will be generated using numbers, letters and special characters.
public generateRandomString ( integer $length, string $chars = '' ) : string
$length integer Length of the generated string.
$chars string A string containing a list of chars that will be uses for generating the random string.
Результат string Random string with the given $length containing only the provided set of $chars.

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

This method is ok to use for generating random user passwords. (which, of course, should be changed after first login).
public generateUserReadableString ( integer $length ) : string
$length integer Length of the random string.
Результат string Random string with the given $length.

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

Verify if the given $hash matches the given $password.
public verifyPasswordHash ( string $password, string $hash ) : boolean
$password string Original, un-hashed, password.
$hash string Hash string to which the check should be made
Результат boolean True if $password matches the $hash, otherwise false is returned.

Описание свойств

$cipher защищенное свойство

* @var string Mcrypt cipher used for encryption and decryption.
protected string $cipher
Результат string

$cipherMode защищенное свойство

Mcrypt mode used for encryption and decryption.
protected $cipherMode

$passwordAlgo защищенное свойство

Password algorithm used by password_hash
protected $passwordAlgo