Phalcon encryption
NOTE
All classes are prefixed with Phalcon
Encryption\Crypt¶
Class Source on GitHub
Provides encryption capabilities to Phalcon applications.
use Phalcon\Crypt;
$crypt = new Crypt();
$crypt->setCipher("aes-256-ctr");
$key =
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3";
$input = "The message to be encrypted";
$encrypted = $crypt->encrypt($input, $key);
echo $crypt->decrypt($encrypted, $key);
Phalcon\Encryption\Crypt— implementsPhalcon\Encryption\Crypt\CryptInterface
Uses Phalcon\Encryption\Crypt\CryptInterface · Phalcon\Encryption\Crypt\Exception\DecryptionFailed · Phalcon\Encryption\Crypt\Exception\EmptyDecryptionKey · Phalcon\Encryption\Crypt\Exception\EmptyEncryptionKey · Phalcon\Encryption\Crypt\Exception\EncryptionFailed · Phalcon\Encryption\Crypt\Exception\Exception · Phalcon\Encryption\Crypt\Exception\InvalidAuthTagLength · Phalcon\Encryption\Crypt\Exception\InvalidDecryptLength · Phalcon\Encryption\Crypt\Exception\InvalidPaddingSize · Phalcon\Encryption\Crypt\Exception\IvLengthCalculationFailed · Phalcon\Encryption\Crypt\Exception\Mismatch · Phalcon\Encryption\Crypt\Exception\MissingAuthData · Phalcon\Encryption\Crypt\Exception\MissingOpensslExtension · Phalcon\Encryption\Crypt\Exception\RandomBytesGenerationFailed · Phalcon\Encryption\Crypt\Exception\UnsupportedAlgorithm · Phalcon\Encryption\Crypt\PadFactory
Method Summary¶
public __construct(string $cipher = self::DEFAULT_CIPHER,bool $useSigning = true,PadFactory $padFactory = null) Crypt constructor. public string decrypt(string $input,string $key = null) Decrypts an encrypted text. public string decryptBase64(string $input,string $key = null,bool $safe = false) Decrypt a text that is coded as a base64 string. public string encrypt(string $input,string $key = null) Encrypts a text. public string encryptBase64(string $input,string $key = null,bool $safe = false) Encrypts a text returning the result as a base64 string. public string getAuthData() Returns the auth data public string getAuthTag() Returns the auth tag public int getAuthTagLength() Returns the auth tag length public array getAvailableCiphers() Returns a list of available ciphers. public array getAvailableHashAlgorithms() Return a list of registered hashing algorithms suitable for hash_hmac. public string getCipher() Returns the current cipher public string getHashAlgorithm() Get the name of hashing algorithm. public string getKey() Returns the encryption key public bool isValidDecryptLength( string $input ) Returns if the input length for decryption is valid or not public CryptInterface setAuthData( string $data ) public CryptInterface setAuthTag( string $tag ) public CryptInterface setAuthTagLength( int $length ) public CryptInterface setCipher( string $cipher ) Sets the cipher algorithm for data encryption and decryption. public static setHashAlgorithm( string $hashAlgorithm ) Set the name of hashing algorithm. public CryptInterface setKey( string $key ) Sets the encryption key. public CryptInterface setPadding( int $scheme ) Changes the padding scheme used. public CryptInterface useSigning( bool $useSigning ) Sets if the calculating message digest must used. protected void checkCipherHashIsAvailable(string $cipher,string $type) Checks if a cipher or a hash algorithm is available protected string cryptPadText(string $input,string $mode,int $blockSize,int $paddingType) Pads texts before encryption. See protected string cryptUnpadText(string $input,string $mode,int $blockSize,int $paddingType) Removes a padding from a text. protected string decryptGcmCcmAuth(string $mode,string $cipherText,string $decryptKey,string $iv) protected string decryptGetUnpadded(string $mode,int $blockSize,string $decrypted) protected string encryptGcmCcm(string $mode,string $padded,string $encryptKey,string $iv) protected string encryptGetPadded(string $mode,string $input,int $blockSize) protected static initializeAvailableCiphers() Initialize available cipher algorithms. protected bool phpFunctionExists( string $name ) @todo to be removed when we get traits protected int|bool phpOpensslCipherIvLength( string $cipher ) protected phpOpensslRandomPseudoBytes( int $length ) Constants¶
string DEFAULT_ALGORITHM = "sha256" string DEFAULT_CIPHER = "aes-256-cfb" int PADDING_ANSI_X_923 = 1 Padding int PADDING_DEFAULT = 0 int PADDING_ISO_10126 = 3 int PADDING_ISO_IEC_7816_4 = 4 int PADDING_PKCS7 = 2 int PADDING_SPACE = 6 int PADDING_ZERO = 5 Properties¶
protected string $authData = "" protected string $authTag = "" protected int $authTagLength = 16 protected array $availableCiphers = [] Available cipher methods. protected string $cipher = self::DEFAULT_CIPHER protected string $hashAlgorithm = self::DEFAULT_ALGORITHM The name of hashing algorithm. protected array $hashLengthCache = [] Memoized strlen(hash($algo, "", true)) results, keyed by algorithm name. The hash output length is deterministic for a given algorithm, so this collapses the per-decrypt strlen+hash call to a single hash lookup after warm-up. protected int $ivLength = 16 The cipher iv length. protected string $key = "" protected PadFactory $padFactory protected int $padding = 0 protected bool $useSigning = true Whether calculating message digest enabled or not. Methods¶
__construct()¶
public function __construct(
string $cipher = self::DEFAULT_CIPHER,
bool $useSigning = true,
PadFactory $padFactory = null
);
Crypt constructor.
decrypt()¶
Decrypts an encrypted text.
$encrypted = $crypt->decrypt(
$encrypted,
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3"
);
decryptBase64()¶
Decrypt a text that is coded as a base64 string.
encrypt()¶
Encrypts a text.
$encrypted = $crypt->encrypt(
"Top secret",
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3"
);
encryptBase64()¶
Encrypts a text returning the result as a base64 string.
getAuthData()¶
Returns the auth data
getAuthTag()¶
Returns the auth tag
getAuthTagLength()¶
Returns the auth tag length
getAvailableCiphers()¶
Returns a list of available ciphers.
getAvailableHashAlgorithms()¶
Return a list of registered hashing algorithms suitable for hash_hmac.
getCipher()¶
Returns the current cipher
getHashAlgorithm()¶
Get the name of hashing algorithm.
getKey()¶
Returns the encryption key
isValidDecryptLength()¶
Returns if the input length for decryption is valid or not (number of bytes required by the cipher).
setAuthData()¶
setAuthTag()¶
setAuthTagLength()¶
setCipher()¶
Sets the cipher algorithm for data encryption and decryption.
setHashAlgorithm()¶
Set the name of hashing algorithm.
setKey()¶
Sets the encryption key.
The $key should have been previously generated in a cryptographically safe way.
Bad key: "le password"
Better (but still unsafe) -> "#1dj8$=dp?.ak//j1V$~%*0X"
Good key: "T4\xb1\x8d\xa9\x98\x05\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3"
setPadding()¶
Changes the padding scheme used.
useSigning()¶
Sets if the calculating message digest must used.
checkCipherHashIsAvailable()¶
Checks if a cipher or a hash algorithm is available
cryptPadText()¶
protected function cryptPadText(
string $input,
string $mode,
int $blockSize,
int $paddingType
): string;
Pads texts before encryption. See cryptopad
cryptUnpadText()¶
protected function cryptUnpadText(
string $input,
string $mode,
int $blockSize,
int $paddingType
): string;
Removes a padding from a text.
If the function detects that the text was not padded, it will return it unmodified.
decryptGcmCcmAuth()¶
protected function decryptGcmCcmAuth(
string $mode,
string $cipherText,
string $decryptKey,
string $iv
): string;
decryptGetUnpadded()¶
encryptGcmCcm()¶
protected function encryptGcmCcm(
string $mode,
string $padded,
string $encryptKey,
string $iv
): string;
encryptGetPadded()¶
initializeAvailableCiphers()¶
Initialize available cipher algorithms.
phpFunctionExists()¶
@todo to be removed when we get traits
phpOpensslCipherIvLength()¶
phpOpensslRandomPseudoBytes()¶
Encryption\Crypt\CryptInterface¶
Interface Source on GitHub
Interface for Phalcon\Crypt
Phalcon\Contracts\Encryption\Crypt\CryptPhalcon\Encryption\Crypt\CryptInterface
Uses Phalcon\Contracts\Encryption\Crypt\Crypt
Encryption\Crypt\Exception\DecryptionFailed¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\DecryptionFailed
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\EmptyDecryptionKey¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\EmptyDecryptionKey
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\EmptyEncryptionKey¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\EmptyEncryptionKey
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\EncryptionFailed¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\EncryptionFailed
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\Exception¶
Class Source on GitHub
Exceptions thrown in Phalcon\Crypt use this class
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\DecryptionFailedPhalcon\Encryption\Crypt\Exception\EmptyDecryptionKeyPhalcon\Encryption\Crypt\Exception\EmptyEncryptionKeyPhalcon\Encryption\Crypt\Exception\EncryptionFailedPhalcon\Encryption\Crypt\Exception\InvalidAuthTagLengthPhalcon\Encryption\Crypt\Exception\InvalidDecryptLengthPhalcon\Encryption\Crypt\Exception\InvalidPaddingSizePhalcon\Encryption\Crypt\Exception\IvLengthCalculationFailedPhalcon\Encryption\Crypt\Exception\MismatchPhalcon\Encryption\Crypt\Exception\MissingAuthDataPhalcon\Encryption\Crypt\Exception\MissingOpensslExtensionPhalcon\Encryption\Crypt\Exception\RandomBytesGenerationFailedPhalcon\Encryption\Crypt\Exception\UnsupportedAlgorithm
Encryption\Crypt\Exception\InvalidAuthTagLength¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\InvalidAuthTagLength
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\InvalidDecryptLength¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\InvalidDecryptLength
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\InvalidPaddingSize¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\InvalidPaddingSize
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\IvLengthCalculationFailed¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\IvLengthCalculationFailed
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\Mismatch¶
Class Source on GitHub
Exceptions thrown in Phalcon\Crypt will use this class.
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\Mismatch
Encryption\Crypt\Exception\MissingAuthData¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\MissingAuthData
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\MissingOpensslExtension¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\MissingOpensslExtension
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\RandomBytesGenerationFailed¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\RandomBytesGenerationFailed
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\Exception\UnsupportedAlgorithm¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Crypt\Exception\ExceptionPhalcon\Encryption\Crypt\Exception\UnsupportedAlgorithm
Method Summary¶
Methods¶
__construct()¶
Encryption\Crypt\PadFactory¶
Class Source on GitHub
Factory for creating pad classes
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Encryption\Crypt\PadFactory
Uses Phalcon\Encryption\Crypt · Phalcon\Encryption\Crypt\Padding\PadInterface · Phalcon\Factory\AbstractFactory
Method Summary¶
public __construct( array $services = [] ) AdapterFactory constructor. public PadInterface newInstance( string $name ) Create a new instance of the adapter public string padNumberToService( int $number ) Gets a Crypt pad constant and returns the unique service name for the protected array getServices() Properties¶
protected string $exception = "Phalcon\\Encryption\\Crypt\\Exception\\Exception" Methods¶
__construct()¶
AdapterFactory constructor.
newInstance()¶
Create a new instance of the adapter
padNumberToService()¶
Gets a Crypt pad constant and returns the unique service name for the padding class
getServices()¶
Encryption\Crypt\Padding\Ansi¶
Class Source on GitHub
Class Ansi
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\Ansi— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Crypt\Padding\Iso10126¶
Class Source on GitHub
Class Iso10126
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\Iso10126— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Crypt\Padding\IsoIek¶
Class Source on GitHub
Class IsoIek
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\IsoIek— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Crypt\Padding\Noop¶
Class Source on GitHub
Class Noop
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\Noop— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Crypt\Padding\PadInterface¶
Interface Source on GitHub
Interface for Phalcon\Encryption\Crypt\Padding
Phalcon\Contracts\Encryption\Crypt\Padding\PadPhalcon\Encryption\Crypt\Padding\PadInterface
Uses Phalcon\Contracts\Encryption\Crypt\Padding\Pad
Encryption\Crypt\Padding\Pkcs7¶
Class Source on GitHub
Class Pkcs7
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\Pkcs7— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Crypt\Padding\Space¶
Class Source on GitHub
Class Space
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\Space— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Crypt\Padding\Zero¶
Class Source on GitHub
Class Zero
@package Phalcon\Encryption\Crypt\Padding
Phalcon\Encryption\Crypt\Padding\Zero— implementsPhalcon\Encryption\Crypt\Padding\PadInterface
Method Summary¶
Methods¶
pad()¶
unpad()¶
Encryption\Security¶
Class Source on GitHub
This component provides a set of functions to improve the security in Phalcon applications
$login = $this->request->getPost("login");
$password = $this->request->getPost("password");
$user = Users::findFirstByLogin($login);
if ($user) {
if ($this->security->checkHash($password, $user->password)) {
// The password is valid
}
}
stdClassPhalcon\Di\AbstractInjectionAwarePhalcon\Encryption\Security— implementsPhalcon\Contracts\Encryption\Security\Security
Uses Phalcon\Contracts\Encryption\Security\Security · Phalcon\Di\AbstractInjectionAware · Phalcon\Di\DiInterface · Phalcon\Encryption\Security\Exception · Phalcon\Encryption\Security\Exceptions\UnknownHashAlgorithm · Phalcon\Encryption\Security\Random · Phalcon\Http\RequestInterface · Phalcon\Session\ManagerInterface
Method Summary¶
public __construct(SessionInterface $session = null,RequestInterface $request = null) Security constructor. public bool checkHash(string $password,string $passwordHash,int $maxPassLength = 0) Checks a plain text password and its hash version to check if the public bool checkToken(string $tokenKey = null,mixed $tokenValue = null,bool $destroyIfValid = true) Check if the CSRF token sent in the request is the same that the current public string computeHmac(string $data,string $key,string $algorithm,bool $raw = false) Computes a HMAC public static destroyToken() Removes the value of the CSRF token and key from session public int getDefaultHash() Returns the default hash public array getHashInformation( string $hash ) Returns information regarding a hash public Random getRandom() Returns a secure random number generator instance public int getRandomBytes() Returns a number of bytes to be generated by the openssl pseudo random public string|null getRequestToken() Returns the value of the CSRF token for the current request. public string getSaltBytes( int $numberBytes = 0 ) Generate a >22-length pseudo random string to be used as salt for public string|null getSessionToken() Returns the value of the CSRF token in session public string|null getToken() Generates a pseudo random token value to be used as input's value in a public string|null getTokenKey() Generates a pseudo random token key to be used as input's name in a CSRF public int getWorkFactor() public string hash(string $password,array $options = []) Creates a password hash using bcrypt with a pseudo random salt public bool isLegacyHash( string $passwordHash ) Checks if a password hash is a valid bcrypt's hash public static refreshToken() Forces the regeneration of the CSRF token and key, writing the new public static setAutoRefresh( bool $autoRefresh ) Toggles automatic regeneration of the CSRF token on every call to public static setDefaultHash( int $defaultHash ) Sets the default hash public static setRandomBytes( int $randomBytes ) Sets a number of bytes to be generated by the openssl pseudo random public static setWorkFactor( int $workFactor ) Sets the work factor protected getLocalService(string $name,string $property) Constants¶
int CRYPT_ARGON2I = 10 int CRYPT_ARGON2ID = 11 int CRYPT_BCRYPT = 0 int CRYPT_BLOWFISH = 4 int CRYPT_BLOWFISH_A = 5 int CRYPT_BLOWFISH_X = 6 int CRYPT_BLOWFISH_Y = 7 int CRYPT_DEFAULT = 0 int CRYPT_EXT_DES = 2 int CRYPT_MD5 = 3 int CRYPT_SHA256 = 8 int CRYPT_SHA512 = 9 int CRYPT_STD_DES = 1 Properties¶
protected bool $autoRefresh = true protected int $defaultHash = self::CRYPT_DEFAULT protected int $numberBytes = 16 protected Random $random protected string|null $requestToken = null protected string|null $token = null protected string|null $tokenKey = null protected string $tokenKeySessionId = "$PHALCON/CSRF/KEY$" protected string $tokenValueSessionId = "$PHALCON/CSRF$" protected int $workFactor = 10 Methods¶
__construct()¶
Security constructor.
checkHash()¶
Checks a plain text password and its hash version to check if the password matches
checkToken()¶
public function checkToken(
string $tokenKey = null,
mixed $tokenValue = null,
bool $destroyIfValid = true
): bool;
Check if the CSRF token sent in the request is the same that the current in session
computeHmac()¶
public function computeHmac(
string $data,
string $key,
string $algorithm,
bool $raw = false
): string;
Computes a HMAC
destroyToken()¶
Removes the value of the CSRF token and key from session
getDefaultHash()¶
Returns the default hash
getHashInformation()¶
Returns information regarding a hash
getRandom()¶
Returns a secure random number generator instance
getRandomBytes()¶
Returns a number of bytes to be generated by the openssl pseudo random generator
getRequestToken()¶
Returns the value of the CSRF token for the current request.
getSaltBytes()¶
Generate a >22-length pseudo random string to be used as salt for passwords
getSessionToken()¶
Returns the value of the CSRF token in session
getToken()¶
Generates a pseudo random token value to be used as input's value in a CSRF check
getTokenKey()¶
Generates a pseudo random token key to be used as input's name in a CSRF check
getWorkFactor()¶
hash()¶
Creates a password hash using bcrypt with a pseudo random salt
Any defaultHash value that is not explicitly handled (including the deprecated, unimplemented constants) resolves to bcrypt.
isLegacyHash()¶
Checks if a password hash is a valid bcrypt's hash
refreshToken()¶
Forces the regeneration of the CSRF token and key, writing the new values to the session even when auto-refresh has been disabled. Useful after a successful login or any other state change where rotating the token is appropriate.
setAutoRefresh()¶
Toggles automatic regeneration of the CSRF token on every call to getToken() / getTokenKey(). When set to false, existing session values are reused (no session write), and a new token is only minted when none is present or refreshToken() is called explicitly.
setDefaultHash()¶
Sets the default hash
setRandomBytes()¶
Sets a number of bytes to be generated by the openssl pseudo random generator
setWorkFactor()¶
Sets the work factor
getLocalService()¶
Encryption\Security\Exception¶
Class Source on GitHub
Phalcon\Encryption\Security\Exception
Exceptions thrown in Phalcon\Security will use this class
\ExceptionPhalcon\Encryption\Security\Exception
Encryption\Security\Exceptions\InvalidRandomInput¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Security\ExceptionPhalcon\Encryption\Security\Exceptions\InvalidRandomInput
Uses Phalcon\Encryption\Security\Exception
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\Exceptions\UnknownHashAlgorithm¶
Class Source on GitHub
\ExceptionPhalcon\Encryption\Security\ExceptionPhalcon\Encryption\Security\Exceptions\UnknownHashAlgorithm
Uses Phalcon\Encryption\Security\Exception
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Builder¶
Class Source on GitHub
JWT Builder
@link https://tools.ietf.org/html/rfc7519
Phalcon\Encryption\Security\JWT\Builder
Uses Phalcon\Encryption\Security\JWT\Exceptions\EmptyPassphrase · Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudience · Phalcon\Encryption\Security\JWT\Exceptions\InvalidExpirationTime · Phalcon\Encryption\Security\JWT\Exceptions\InvalidNotBefore · Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException · Phalcon\Encryption\Security\JWT\Exceptions\WeakPassphrase · Phalcon\Encryption\Security\JWT\Signer\SignerInterface · Phalcon\Encryption\Security\JWT\Token\Enum · Phalcon\Encryption\Security\JWT\Token\Item · Phalcon\Encryption\Security\JWT\Token\Signature · Phalcon\Encryption\Security\JWT\Token\Token · Phalcon\Support\Collection · Phalcon\Support\Collection\CollectionInterface · Phalcon\Support\Helper\Json\Encode
Method Summary¶
public __construct( SignerInterface $signer ) Builder constructor. public static addClaim(string $name,mixed $value) Adds a custom claim public static addHeader(string $name,mixed $value) Adds a custom claim public getAudience() public array getClaims() public string|null getContentType() public int|null getExpirationTime() public array getHeaders() public string|null getId() public int|null getIssuedAt() public string|null getIssuer() public int|null getNotBefore() public string getPassphrase() public string|null getSubject() public Token getToken() public static init() public static setAudience( mixed $audience ) The "aud" (audience) claim identifies the recipients that the JWT is public static setContentType( string $contentType ) Sets the content type header 'cty' public static setExpirationTime( int $timestamp ) The "exp" (expiration time) claim identifies the expiration time on public static setId( string $jwtId ) The "jti" (JWT ID) claim provides a unique identifier for the JWT. public static setIssuedAt( int $timestamp ) The "iat" (issued at) claim identifies the time at which the JWT was public static setIssuer( string $issuer ) The "iss" (issuer) claim identifies the principal that issued the public static setNotBefore( int $timestamp ) The "nbf" (not before) claim identifies the time before which the JWT public static setPassphrase( string $passphrase ) public static setSubject( string $subject ) The "sub" (subject) claim identifies the principal that is the protected Builder setClaim(string $name,mixed $value) Sets a registered claim Methods¶
__construct()¶
Builder constructor.
addClaim()¶
Adds a custom claim
addHeader()¶
Adds a custom claim
getAudience()¶
getClaims()¶
getContentType()¶
getExpirationTime()¶
getHeaders()¶
getId()¶
getIssuedAt()¶
getIssuer()¶
getNotBefore()¶
getPassphrase()¶
getSubject()¶
getToken()¶
init()¶
setAudience()¶
The "aud" (audience) claim identifies the recipients that the JWT is intended for. Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the "aud" claim when this claim is present, then the JWT MUST be rejected. In the general case, the "aud" value is an array of case- sensitive strings, each containing a StringOrURI value. In the special case when the JWT has one audience, the "aud" value MAY be a single case-sensitive string containing a StringOrURI value. The interpretation of audience values is generally application specific. Use of this claim is OPTIONAL.
setContentType()¶
Sets the content type header 'cty'
setExpirationTime()¶
The "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing of the "exp" claim requires that the current date/time MUST be before the expiration date/time listed in the "exp" claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.
setId()¶
The "jti" (JWT ID) claim provides a unique identifier for the JWT. The identifier value MUST be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object; if the application uses multiple issuers, collisions MUST be prevented among values produced by different issuers as well. The "jti" claim can be used to prevent the JWT from being replayed. The "jti" value is a case- sensitive string. Use of this claim is OPTIONAL.
setIssuedAt()¶
The "iat" (issued at) claim identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.
setIssuer()¶
The "iss" (issuer) claim identifies the principal that issued the JWT. The processing of this claim is generally application specific. The "iss" value is a case-sensitive string containing a StringOrURI value. Use of this claim is OPTIONAL.
setNotBefore()¶
The "nbf" (not before) claim identifies the time before which the JWT MUST NOT be accepted for processing. The processing of the "nbf" claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the "nbf" claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.
setPassphrase()¶
setSubject()¶
The "sub" (subject) claim identifies the principal that is the subject of the JWT. The claims in a JWT are normally statements about the subject. The subject value MUST either be scoped to be locally unique in the context of the issuer or be globally unique. The processing of this claim is generally application specific. The "sub" value is a case-sensitive string containing a StringOrURI value. Use of this claim is OPTIONAL.
setClaim()¶
Sets a registered claim
Encryption\Security\JWT\Exceptions\EmptyPassphrase¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\EmptyPassphrase
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\InvalidAudience¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\InvalidAudience
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\InvalidAudienceType¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\InvalidAudienceType
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\InvalidClaims¶
Class Source on GitHub
InvalidArgumentExceptionPhalcon\Encryption\Security\JWT\Exceptions\InvalidClaims
Uses InvalidArgumentException
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\InvalidExpirationTime¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\InvalidExpirationTime
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\InvalidHeader¶
Class Source on GitHub
InvalidArgumentExceptionPhalcon\Encryption\Security\JWT\Exceptions\InvalidHeader
Uses InvalidArgumentException
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\InvalidNotBefore¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\InvalidNotBefore
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\MalformedJwtString¶
Class Source on GitHub
InvalidArgumentExceptionPhalcon\Encryption\Security\JWT\Exceptions\MalformedJwtString
Uses InvalidArgumentException
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\MissingJwtTypHeader¶
Class Source on GitHub
InvalidArgumentExceptionPhalcon\Encryption\Security\JWT\Exceptions\MissingJwtTypHeader
Uses InvalidArgumentException
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException¶
Class Source on GitHub
Exception thrown when the algorithm is not supported for JWT
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException
Uses Exception
Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmExceptionPhalcon\Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Exceptions\ValidatorException¶
Class Source on GitHub
Exception thrown when the validation does not pass for JWT
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\EmptyPassphrasePhalcon\Encryption\Security\JWT\Exceptions\InvalidAudiencePhalcon\Encryption\Security\JWT\Exceptions\InvalidAudienceTypePhalcon\Encryption\Security\JWT\Exceptions\InvalidExpirationTimePhalcon\Encryption\Security\JWT\Exceptions\InvalidNotBeforePhalcon\Encryption\Security\JWT\Exceptions\WeakPassphrase
Uses Exception
Encryption\Security\JWT\Exceptions\WeakPassphrase¶
Class Source on GitHub
ExceptionPhalcon\Encryption\Security\JWT\Exceptions\ValidatorExceptionPhalcon\Encryption\Security\JWT\Exceptions\WeakPassphrase
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\JWT\Signer\AbstractSigner¶
Abstract Source on GitHub
Abstract class helping with the signer classes
Phalcon\Encryption\Security\JWT\Signer\AbstractSigner— implementsPhalcon\Encryption\Security\JWT\Signer\SignerInterface
Method Summary¶
Properties¶
protected string $algorithm = "" Methods¶
getAlgorithm()¶
Encryption\Security\JWT\Signer\Hmac¶
Class Source on GitHub
HMAC signing class
Phalcon\Encryption\Security\JWT\Signer\AbstractSignerPhalcon\Encryption\Security\JWT\Signer\Hmac
Uses Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException · Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm
Method Summary¶
public __construct( string $algo = "sha512" ) Hmac constructor. public string getAlgHeader() Return the value that is used for the "alg" header public string sign(string $payload,string $passphrase) Sign a payload using the passphrase public bool verify(string $source,string $payload,string $passphrase) Verify a passed source with a payload and passphrase Methods¶
__construct()¶
Hmac constructor.
getAlgHeader()¶
Return the value that is used for the "alg" header
sign()¶
Sign a payload using the passphrase
verify()¶
Verify a passed source with a payload and passphrase
Encryption\Security\JWT\Signer\None¶
Class Source on GitHub
No signing class
Phalcon\Encryption\Security\JWT\Signer\None— implementsPhalcon\Encryption\Security\JWT\Signer\SignerInterface
Method Summary¶
public string getAlgHeader() Return the value that is used for the "alg" header public string getAlgorithm() Return the algorithm used public string sign(string $payload,string $passphrase) Sign a payload using the passphrase public bool verify(string $source,string $payload,string $passphrase) Verify a passed source with a payload and passphrase Methods¶
getAlgHeader()¶
Return the value that is used for the "alg" header
getAlgorithm()¶
Return the algorithm used
sign()¶
Sign a payload using the passphrase
verify()¶
Verify a passed source with a payload and passphrase
Encryption\Security\JWT\Signer\SignerInterface¶
Interface Source on GitHub
Interface for JWT Signer classes
Phalcon\Contracts\Encryption\Security\JWT\Signer\SignerPhalcon\Encryption\Security\JWT\Signer\SignerInterface
Uses Phalcon\Contracts\Encryption\Security\JWT\Signer\Signer
Encryption\Security\JWT\Token\AbstractItem¶
Abstract Source on GitHub
Abstract helper class for Tokens
Phalcon\Encryption\Security\JWT\Token\AbstractItem
Method Summary¶
Properties¶
protected array $data = [] Methods¶
getEncoded()¶
Encryption\Security\JWT\Token\Enum¶
Class Source on GitHub
Constants for Tokens. It offers constants for Headers as well as Claims
@link https://tools.ietf.org/html/rfc7519
Phalcon\Encryption\Security\JWT\Token\Enum
Constants¶
string ALGO = "alg" string AUDIENCE = "aud" Claims string CONTENT_TYPE = "cty" string EXPIRATION_TIME = "exp" string ID = "jti" string ISSUED_AT = "iat" string ISSUER = "iss" string NOT_BEFORE = "nbf" string SUBJECT = "sub" string TYPE = "typ" Headers Encryption\Security\JWT\Token\Item¶
Class Source on GitHub
Storage class for a Token Item
Phalcon\Encryption\Security\JWT\Token\AbstractItemPhalcon\Encryption\Security\JWT\Token\Item
Method Summary¶
public __construct(array $payload,string $encoded) Item constructor. public mixed|null get(string $name,mixed $defaultValue = null) public array getPayload() public bool has( string $name ) Methods¶
__construct()¶
Item constructor.
get()¶
getPayload()¶
has()¶
Encryption\Security\JWT\Token\Parser¶
Class Source on GitHub
Token Parser class.
It parses a token by validating if it is formed properly and splits it into three parts. The headers are decoded, then the claims and finally the signature. It returns a token object populated with the decoded information.
Phalcon\Encryption\Security\JWT\Token\Parser
Uses InvalidArgumentException · Phalcon\Encryption\Security\JWT\Exceptions\InvalidClaims · Phalcon\Encryption\Security\JWT\Exceptions\InvalidHeader · Phalcon\Encryption\Security\JWT\Exceptions\MalformedJwtString · Phalcon\Encryption\Security\JWT\Exceptions\MissingJwtTypHeader · Phalcon\Support\Helper\Json\Decode
Method Summary¶
public __construct( Decode $decode = null ) public Token parse( string $token ) Parse a token and return it Methods¶
__construct()¶
parse()¶
Parse a token and return it
Encryption\Security\JWT\Token\Signature¶
Class Source on GitHub
Signature class containing the encoded data and the hash.
Phalcon\Encryption\Security\JWT\Token\AbstractItemPhalcon\Encryption\Security\JWT\Token\Signature
Method Summary¶
public __construct(string $hash = "",string $encoded = "") Signature constructor. public string getHash() Methods¶
__construct()¶
Signature constructor.
getHash()¶
Encryption\Security\JWT\Token\Token¶
Class Source on GitHub
Token Class.
A container for Token related data. It stores the claims, headers, signature and payload. It also calculates and returns the token string.
@property Item $claims @property Item $headers @property Signature $signature
@link https://tools.ietf.org/html/rfc7519
Phalcon\Encryption\Security\JWT\Token\Token
Uses Phalcon\Encryption\Security\JWT\Signer\SignerInterface · Phalcon\Encryption\Security\JWT\Validator
Method Summary¶
public __construct(Item $headers,Item $claims,Signature $signature) Token constructor. public Item getClaims() Return the registered claims public Item getHeaders() Return the registered headers public string getPayload() Return the payload public Signature getSignature() Return the signature public string getToken() Return the token public array validate( Validator $validator ) public bool verify(SignerInterface $signer,string $key) Verify the signature Methods¶
__construct()¶
Token constructor.
getClaims()¶
Return the registered claims
getHeaders()¶
Return the registered headers
getPayload()¶
Return the payload
getSignature()¶
Return the signature
getToken()¶
Return the token
validate()¶
verify()¶
Verify the signature
Encryption\Security\JWT\Validator¶
Class Source on GitHub
Class Validator
Phalcon\Encryption\Security\JWT\Validator
Uses DateTimeImmutable · Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudienceType · Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException · Phalcon\Encryption\Security\JWT\Signer\SignerInterface · Phalcon\Encryption\Security\JWT\Token\Enum · Phalcon\Encryption\Security\JWT\Token\Token · Phalcon\Time\Clock\ClockInterface
Method Summary¶
public __construct(Token $token,int $timeShift = 0,ClockInterface $clock = null) Validator constructor. public mixed|null get( string $claim ) Return the value of a claim public array getErrors() Return an array with validation errors (if any) public static set(string $claim,mixed $value) Set the value of a claim, for comparison with the token values public static setToken( Token $token ) Set the token to be validated public static validateAudience( mixed $audience ) Validate the audience public static validateClaim(string $name,mixed $value) Validate a claim public static validateExpiration( int $timestamp ) Validate the expiration time of the token public static validateId( string $id ) Validate the id of the token public static validateIssuedAt( int $timestamp ) Validate the issued at (iat) of the token public static validateIssuer( string $issuer ) Validate the issuer of the token public static validateNotBefore( int $timestamp ) Validate the notbefore (nbf) of the token public static validateSignature(SignerInterface $signer,string $passphrase) Validate the signature of the token Methods¶
__construct()¶
Validator constructor.
get()¶
Return the value of a claim
getErrors()¶
Return an array with validation errors (if any)
set()¶
Set the value of a claim, for comparison with the token values
setToken()¶
Set the token to be validated
validateAudience()¶
Validate the audience
validateClaim()¶
Validate a claim
validateExpiration()¶
Validate the expiration time of the token
validateId()¶
Validate the id of the token
validateIssuedAt()¶
Validate the issued at (iat) of the token
validateIssuer()¶
Validate the issuer of the token
validateNotBefore()¶
Validate the notbefore (nbf) of the token
validateSignature()¶
Validate the signature of the token
Encryption\Security\Random¶
Class Source on GitHub
Phalcon\Encryption\Security\Random
Secure random number generator class.
Provides secure random number generator which is suitable for generating session key in HTTP cookies, etc.
Phalcon\Encryption\Security\Random could be mainly useful for:
- Key generation (e.g. generation of complicated keys)
- Generating random passwords for new user accounts
- Encryption systems
$random = new \Phalcon\Encryption\Security\Random();
// Random binary string
$bytes = $random->bytes();
// Random hex string
echo $random->hex(10); // a29f470508d5ccb8e289
echo $random->hex(10); // 533c2f08d5eee750e64a
echo $random->hex(11); // f362ef96cb9ffef150c9cd
echo $random->hex(12); // 95469d667475125208be45c4
echo $random->hex(13); // 05475e8af4a34f8f743ab48761
// Random base62 string
echo $random->base62(); // z0RkwHfh8ErDM1xw
// Random base64 string
echo $random->base64(12); // XfIN81jGGuKkcE1E
echo $random->base64(12); // 3rcq39QzGK9fUqh8
echo $random->base64(); // DRcfbngL/iOo9hGGvy1TcQ==
echo $random->base64(16); // SvdhPcIHDZFad838Bb0Swg==
// Random URL-safe base64 string
echo $random->base64Safe(); // PcV6jGbJ6vfVw7hfKIFDGA
echo $random->base64Safe(); // GD8JojhzSTrqX7Q8J6uug
echo $random->base64Safe(8); // mGyy0evy3ok
echo $random->base64Safe(null, true); // DRrAgOFkS4rvRiVHFefcQ==
// Random UUID (version 4) - returns a string
echo $random->uuid(); // db082997-2572-4e2c-a046-5eefe97b1235
echo $random->uuid(); // da2aa0e2-b4d0-4e3c-99f5-f5ef62c57fe2
// For other UUID versions (1, 3, 5, 6, 7) or object-based access use the
// Phalcon\Encryption\Security\Uuid factory instead:
//
// $uuid = new \Phalcon\Encryption\Security\Uuid();
// echo $uuid->v1(); // time-based
// echo $uuid->v6(); // reordered time-based (sortable)
// echo $uuid->v7(); // Unix-timestamp based (sortable)
// Random number between 0 and $len
echo $random->number(256); // 84
echo $random->number(256); // 79
echo $random->number(100); // 29
echo $random->number(300); // 40
// Random base58 string
echo $random->base58(); // 4kUgL2pdQMSCQtjE
echo $random->base58(); // Umjxqf7ZPwh765yR
echo $random->base58(24); // qoXcgmw4A9dys26HaNEdCRj9
echo $random->base58(7); // 774SJD3vgP
This class partially borrows SecureRandom library from Ruby
@link https://ruby-doc.org/stdlib-2.2.2/libdoc/securerandom/rdoc/SecureRandom.html
Phalcon\Encryption\Security\Random
Uses Phalcon\Encryption\Security\Exceptions\InvalidRandomInput
Method Summary¶
public string base58( int $len = 16 ) Generates a random base58 string public string base62( int $len = 16 ) Generates a random base62 string public string base64( int $len = 16 ) Generates a random base64 string public string base64Safe(int $len = 16,bool $padding = false) Generates a random URL-safe base64 string public string bytes( int $len = 16 ) Generates a random binary string public string hex( int $len = 16 ) Generates a random hex string public int number( int $len ) Generates a random number between 0 and $len public string uuid() Generates a v4 random UUID (Universally Unique IDentifier) protected string base(string $alphabet,int $base,mixed $number = 16) Generates a random string based on the number ($base) of characters Methods¶
base58()¶
Generates a random base58 string
The result may contain alphanumeric characters except 0, O, I and l.
It is similar to Phalcon\Encryption\Security\Random::base64() but has been modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed.
@see \Phalcon\Encryption\Security\Random:base64 @link https://en.wikipedia.org/wiki/Base58
base62()¶
Generates a random base62 string
It is similar to Phalcon\Encryption\Security\Random::base58() but has been modified to provide the largest value that can safely be used in URLs without needing to take extra characters into consideration because it is [A-Za-z0-9].
@see \Phalcon\Encryption\Security\Random:base58
base64()¶
Generates a random base64 string
The length of the result string is usually greater of $len. Size formula: 4 * ($len / 3) rounded up to a multiple of 4.
base64Safe()¶
Generates a random URL-safe base64 string
The length of the result string is usually greater of $len.
By default, padding is not generated because "=" may be used as a URL delimiter. The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if $padding is true. See RFC 3548 for the definition of URL-safe base64.
$random = new \Phalcon\Encryption\Security\Random();
echo $random->base64Safe(); // GD8JojhzSTrqX7Q8J6uug
@link https://www.ietf.org/rfc/rfc3548.txt
bytes()¶
Generates a random binary string
The Random::bytes method returns a string and accepts as input an int representing the length in bytes to be returned.
If $len is not specified, 16 is assumed. It may be larger in future. The result may contain any byte: "x00" - "xFF".
$random = new \Phalcon\Encryption\Security\Random();
$bytes = $random->bytes();
var_dump(bin2hex($bytes));
// Possible output: string(32) "00f6c04b144b41fad6a59111c126e1ee"
hex()¶
Generates a random hex string
The length of the result string is usually greater of $len.
number()¶
Generates a random number between 0 and $len
Returns an integer: 0 <= result <= $len.
uuid()¶
Generates a v4 random UUID (Universally Unique IDentifier)
The version 4 UUID is purely random (except the version). It does not contain meaningful information such as MAC address, time, etc. See RFC 4122 for details of UUID.
Delegates to Phalcon\Encryption\Security\Uuid::v4(). For other UUID versions or object-based access use that class directly.
$random = new \Phalcon\Encryption\Security\Random();
echo $random->uuid(); // 1378c906-64bb-4f81-a8d6-4ae1bfcdec22
@link https://www.ietf.org/rfc/rfc4122.txt
base()¶
Generates a random string based on the number ($base) of characters ($alphabet).
Encryption\Security\Uuid¶
Class Source on GitHub
Factory that generates UUIDs of versions 1 through 7.
Each call creates a new immutable version object. Cast to string for the UUID value; use the returned object for additional methods such as getDateTime() or getNode().
Phalcon\Encryption\Security\Uuid
Uses Phalcon\Encryption\Security\Uuid\Version1 · Phalcon\Encryption\Security\Uuid\Version3 · Phalcon\Encryption\Security\Uuid\Version4 · Phalcon\Encryption\Security\Uuid\Version5 · Phalcon\Encryption\Security\Uuid\Version6 · Phalcon\Encryption\Security\Uuid\Version7
Method Summary¶
public Version1 v1() Generates a version 1 (time-based) UUID. public Version3 v3(string $namespaceName,string $name) Generates a version 3 (name-based MD5) UUID. public Version4 v4() Generates a version 4 (random) UUID. public Version5 v5(string $namespaceName,string $name) Generates a version 5 (name-based SHA-1) UUID. public Version6 v6() Generates a version 6 (reordered time-based) UUID. public Version7 v7() Generates a version 7 (Unix timestamp) UUID. Methods¶
v1()¶
Generates a version 1 (time-based) UUID.
v3()¶
Generates a version 3 (name-based MD5) UUID.
v4()¶
Generates a version 4 (random) UUID.
v5()¶
Generates a version 5 (name-based SHA-1) UUID.
v6()¶
Generates a version 6 (reordered time-based) UUID.
v7()¶
Generates a version 7 (Unix timestamp) UUID.
Encryption\Security\Uuid\AbstractUuid¶
Abstract Source on GitHub
Shared base for all UUID version objects.
Phalcon\Encryption\Security\Uuid\AbstractUuid— implementsPhalcon\Encryption\Security\Uuid\UuidInterface
Method Summary¶
public string __toString() Returns the UUID string. public string jsonSerialize() Returns the UUID string for JSON serialisation. protected string format( string $hex ) Formats a 32-character hex string as a canonical UUID string. protected NodeProviderInterface getNodeProvider() Returns the shared SysNodeProvider instance, creating it on first call. protected string namespaceToBytes( string $uuid ) Converts a canonical UUID string to its 16-byte binary representation. protected \DateTimeImmutable uuidTimestampToDateTime( mixed $timestamp ) Converts a 60-bit UUID timestamp (100-ns intervals since UUID epoch) to Constants¶
string MAX = "ffffffff-ffff-ffff-ffff-ffffffffffff" string NIL = "00000000-0000-0000-0000-000000000000" int TIME_OFFSET_INT = 0x01B21DD213814000 100-nanosecond intervals between UUID epoch (1582-10-15) and Unix epoch (1970-01-01). Properties¶
protected NodeProviderInterface|null $nodeProvider = null Cached SysNodeProvider instance - shared within the request via static. protected string $uid = "" The generated UUID string. Methods¶
__toString()¶
Returns the UUID string.
jsonSerialize()¶
Returns the UUID string for JSON serialisation.
format()¶
Formats a 32-character hex string as a canonical UUID string.
getNodeProvider()¶
Returns the shared SysNodeProvider instance, creating it on first call. The static property means one discovery per request regardless of how many VersionN objects are constructed.
namespaceToBytes()¶
Converts a canonical UUID string to its 16-byte binary representation.
uuidTimestampToDateTime()¶
Converts a 60-bit UUID timestamp (100-ns intervals since UUID epoch) to a DateTimeImmutable. Used by Version1 and Version6.
Encryption\Security\Uuid\NodeProviderInterface¶
Interface Source on GitHub
Phalcon\Contracts\Encryption\Security\Uuid\NodeProviderPhalcon\Encryption\Security\Uuid\NodeProviderInterface
Uses Phalcon\Contracts\Encryption\Security\Uuid\NodeProvider
Encryption\Security\Uuid\RandomNodeProvider¶
Class Source on GitHub
Generates a random 48-bit node with the multicast bit set.
Used as a fallback when no hardware MAC address is available.
@link https://www.ietf.org/rfc/rfc4122.txt Section 4.5
Phalcon\Encryption\Security\Uuid\RandomNodeProvider— implementsPhalcon\Encryption\Security\Uuid\NodeProviderInterface
Method Summary¶
Methods¶
getNode()¶
Returns a random 12-character hex node with the multicast bit set.
Encryption\Security\Uuid\SysNodeProvider¶
Class Source on GitHub
Discovers the hardware MAC address and returns it as a 12-character hex node.
Two-layer cache: 1. Instance property - free on all calls after the first within this instance. 2. APCu - cross-request within the same PHP-FPM worker (optional).
Falls back to RandomNodeProvider if no valid MAC address is found.
Platform support: Linux - reads /sys/class/net/*\/address macOS - passthru("ifconfig 2>&1") Windows - passthru("ipconfig /all 2>&1") FreeBSD - passthru("netstat -i -f link 2>&1")
Phalcon\Encryption\Security\Uuid\SysNodeProvider— implementsPhalcon\Encryption\Security\Uuid\NodeProviderInterface
Method Summary¶
Methods¶
getNode()¶
Returns the hardware MAC address as a 12-character hex string. Result is cached in the instance property and optionally in APCu.
Encryption\Security\Uuid\TimeBasedUuidInterface¶
Interface Source on GitHub
Phalcon\Contracts\Encryption\Security\Uuid\TimeBasedUuidPhalcon\Encryption\Security\Uuid\TimeBasedUuidInterface
Uses Phalcon\Contracts\Encryption\Security\Uuid\TimeBasedUuid
Encryption\Security\Uuid\UuidInterface¶
Interface Source on GitHub
Marker interface for UUID version adapters.
Also carries the standard RFC 4122 namespace UUIDs as constants.
Phalcon\Contracts\Encryption\Security\Uuid\UuidPhalcon\Encryption\Security\Uuid\UuidInterface
Uses Phalcon\Contracts\Encryption\Security\Uuid\Uuid
Encryption\Security\Uuid\Version1¶
Class Source on GitHub
Generates a version 1 (time-based) UUID.
The timestamp is the number of 100-nanosecond intervals since October 15, 1582 00:00:00.00 UTC (the UUID epoch). The node is resolved via SysNodeProvider (hardware MAC, APCu-cached) with RandomNodeProvider as fallback.
@link https://www.ietf.org/rfc/rfc4122.txt
Phalcon\Encryption\Security\Uuid\AbstractUuidPhalcon\Encryption\Security\Uuid\Version1— implementsPhalcon\Encryption\Security\Uuid\TimeBasedUuidInterface
Method Summary¶
public __construct(\DateTimeInterface $dateTime = null,mixed $node = null) public \DateTimeImmutable getDateTime() Returns a DateTimeImmutable built from the UUID's embedded timestamp. public string getNode() Returns the 12-character hex node embedded in the UUID. Methods¶
__construct()¶
getDateTime()¶
Returns a DateTimeImmutable built from the UUID's embedded timestamp.
getNode()¶
Returns the 12-character hex node embedded in the UUID.
Encryption\Security\Uuid\Version3¶
Class Source on GitHub
Generates a version 3 (name-based MD5) UUID.
Given a namespace UUID and a name string, produces a deterministic UUID by hashing namespace bytes + name with MD5, then stamping version/variant.
@link https://www.ietf.org/rfc/rfc4122.txt
Phalcon\Encryption\Security\Uuid\AbstractUuidPhalcon\Encryption\Security\Uuid\Version3
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\Uuid\Version4¶
Class Source on GitHub
Generates a version 4 (random) UUID.
All 122 non-fixed bits are random. Identical algorithm to Phalcon\Encryption\Security\Random::uuid().
@link https://www.ietf.org/rfc/rfc4122.txt
Phalcon\Encryption\Security\Uuid\AbstractUuidPhalcon\Encryption\Security\Uuid\Version4
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\Uuid\Version5¶
Class Source on GitHub
Generates a version 5 (name-based SHA-1) UUID.
Given a namespace UUID and a name string, produces a deterministic UUID by hashing namespace bytes + name with SHA-1 (first 16 bytes used), then stamping version/variant bits.
@link https://www.ietf.org/rfc/rfc4122.txt
Phalcon\Encryption\Security\Uuid\AbstractUuidPhalcon\Encryption\Security\Uuid\Version5
Method Summary¶
Methods¶
__construct()¶
Encryption\Security\Uuid\Version6¶
Class Source on GitHub
Generates a version 6 (reordered time-based) UUID.
Uses the same 60-bit UUID timestamp as version 1 but rearranges the fields so the most-significant time bits come first, producing UUIDs that sort lexicographically in chronological order.
@link https://www.rfc-editor.org/rfc/rfc9562
Phalcon\Encryption\Security\Uuid\AbstractUuidPhalcon\Encryption\Security\Uuid\Version6— implementsPhalcon\Encryption\Security\Uuid\TimeBasedUuidInterface
Method Summary¶
public __construct() public \DateTimeImmutable getDateTime() Returns a DateTimeImmutable built from the UUID's embedded timestamp. public string getNode() Returns the 12-character hex node embedded in the UUID. Methods¶
__construct()¶
getDateTime()¶
Returns a DateTimeImmutable built from the UUID's embedded timestamp.
getNode()¶
Returns the 12-character hex node embedded in the UUID.
Encryption\Security\Uuid\Version7¶
Class Source on GitHub
Generates a version 7 (Unix timestamp) UUID per RFC 9562.
Layout (128 bits): unix_ts_ms (48) | ver=7 (4) | rand_a (12) | var=10 (2) | rand_b (62)
@link https://www.rfc-editor.org/rfc/rfc9562
Phalcon\Encryption\Security\Uuid\AbstractUuidPhalcon\Encryption\Security\Uuid\Version7