$randomnessSource
$randomnessSource : \CryptoManana\Core\Abstractions\Randomness\AbstractGenerator
The pseudo-random generator service property storage.
The randomness generator.
Class TokenGenerator - Utility class for cryptography token generation.
$randomnessSource : \CryptoManana\Core\Abstractions\Randomness\AbstractGenerator|null
The pseudo-random generator service property storage.
__construct(\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator|null $generator = null)
Container constructor.
\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator|null | $generator | The pseudo-random generator service. |
Initialization validation.
seedRandomGenerator(null|integer $seed = null) : $this
Pass a seed value to the pseudo-randomness generator service.
null|integer | $seed | Seed value in integer format or null for auto-seeding. |
Validation errors and service misuse.
The container object.
setRandomGenerator(\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator $generator) : $this
Setter for the pseudo-random generator service.
\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator | $generator | The pseudo-random generator service. |
The container object.
getRandomGenerator() : \CryptoManana\Core\Abstractions\Randomness\AbstractGenerator|null
Getter for the pseudo-random generator service.
The currently injected pseudo-random generator service.
getTokenString(integer $length = self::MODERATE_TOKEN_LENGTH, boolean|integer $useAlphaNumeric = true) : string
Generate a random token string in alphanumeric or hexadecimal format.
Note: This method can generate HEX output if the $useAlphaNumeric
parameter is
set to false
.
integer | $length | The desired output length (default => 32). |
boolean|integer | $useAlphaNumeric | Flag for switching to alphanumerical (default => true). |
Validation errors.
Randomly generated alphanumeric/hexadecimal token string.
getPasswordString(integer $length = self::MODERATE_PASSWORD_LENGTH, boolean|integer $stronger = true) : string
Generate a random password string.
Note: This method can use more special symbols on generation if the $stronger
parameter is set to true
.
integer | $length | The desired output length (default => 12). |
boolean|integer | $stronger | Flag for using all printable ASCII characters (default => true). |
Validation errors.
Randomly generated password string.
getHashingKey(integer $length = self::DIGESTION_KEY_128_BITS, boolean|integer $printable = true) : string
Generate a random HMAC key for hashing purposes.
Note: The output string can be in raw bytes of the $printable
parameter is set
to true
.
integer | $length | The desired output length (default => 16). |
boolean|integer | $printable | Flag for using only printable characters instead of bytes (default => true). |
Validation errors.
Randomly generated HMAC key.
getHashingSalt(integer $length = self::DIGESTION_SALT_128_BITS, boolean|integer $printable = true) : string
Generate a random salt string for hashing purposes.
Note: The output string can be in raw bytes of the $printable
parameter is set
to true
.
integer | $length | The desired output length (default => 16). |
boolean|integer | $printable | Flag for using only printable characters instead of bytes (default => true). |
Validation errors.
Randomly generated hashing salt.
getEncryptionKey(integer $length = self::SECRET_KEY_128_BITS, boolean|integer $printable = true) : string
Generate a random encryption key for symmetrical cyphers.
Note: The output string can be in raw bytes of the $printable
parameter is set
to true
.
integer | $length | The desired output length (default => 16). |
boolean|integer | $printable | Flag for using only printable characters instead of bytes (default => true). |
Validation errors.
Randomly generated encryption key.
getEncryptionInitializationVector(integer $length = self::IV_128_BITS, boolean|integer $printable = true) : string
Generate a random initialization vector (IV) for encryption purposes.
Note: The output string can be in raw bytes of the $printable
parameter is set
to true
.
integer | $length | The desired output length (default => 16). |
boolean|integer | $printable | Flag for using only printable characters instead of bytes (default => true). |
Validation errors.
Randomly generated encryption initialization vector.
getAsymmetricKeyPair(integer $keySize = self::KEY_PAIR_4096_BITS, integer $algorithmType = self::RSA_KEY_PAIR_TYPE) : \CryptoManana\DataStructures\KeyPair
Generate a random key pair for asymmetrical cyphers.
integer | $keySize | The key size in bits. |
integer | $algorithmType | The asymmetric algorithm type integer code. |
Validation errors.
Randomly generated asymmetric key pair (private and public keys) as an object.
generatePrivateKey(integer $keySize, string $algorithmType) : resource
Internal method for generating a fresh private key pair of the given size and type.
integer | $keySize | The private key size in bits. |
string | $algorithmType | The asymmetric algorithm type. |
Validation or system errors.
The private key resource.
generatePublicKey(integer $keySize, resource $privateKeyResource) : string
Internal method for generating a fresh public key pair of the given size by extracting it from the private key.
integer | $keySize | The private key size in bits. |
resource | $privateKeyResource | The private key resource. |
Validation or system errors.
The extracted public key string.