PHP 클래스 Webiny\Component\Crypt\Bridge\Webiny\Crypt

This is a simple class providing the basic cryptographic methods. The class uses a combination of three different seeds for providing randomness: - MCRYPT_DEV_URANDOM, - mt_rand - microtime For mixing seeds we use a basic combination of mt_rand, shuffle and str_shuffle Password hashing and validation if done using nativ password_hash and password_verify methods. Encoding and decoding is done using mcrypt methods. Notice: This class will provide the neccessary security for most your day-to-day operations, like storing and verifying passwords, generating medium strenght random numbers and strings, and also basic medium encryption and decryption. The library has been tested, but not reviewd by a security expert. If you have any suggestions or improvements to report, feel free to open an issue. If you require a more advanced random library, with higher strenght random generator, we suggest you use https://github.com/ircmaxell/RandomLib.
상속: implements Webiny\Component\Crypt\Bridge\CryptInterface
파일 보기 프로젝트 열기: Webiny/Framework 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( string $passwordAlgo, string $cipherMode, string $cipherBlock ) 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 = 1, integer $max = PHP_INT_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.

비공개 메소드들

메소드 설명
generator ( integer $size ) : string A simple seed generator that uses mcrypt_create_iv (MCRYPT_DEV_URANDOM).
getKeyHash ( string $key ) : string Generates a hash from the given key. The has length is determined by the cipher mode and cipher block.
hkdf ( $key, string $digest = 'sha512', $salt = null, $length = null, string $info = '' ) : string HKDF https://gist.github.com/narfbg/8793435
strLen ( $str )
subStr ( $str, $start, $len = null ) : string Helper function for substr.

메소드 상세

__construct() 공개 메소드

Base constructor
public __construct ( string $passwordAlgo, string $cipherMode, string $cipherBlock )
$passwordAlgo string Password hashing algorithm.
$cipherMode string Cipher mode.
$cipherBlock string Cipher block size.

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.

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 = 1, integer $max = PHP_INT_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.