Properties

$randomnessSource

$randomnessSource : \CryptoManana\Core\Abstractions\Randomness\AbstractGenerator

The pseudo-random generator service property storage.

The randomness generator.

Type

\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator — The pseudo-random generator service.

Methods

__construct()

__construct(\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator|null  $generator = null) 

Container constructor.

Parameters

\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator|null $generator

The pseudo-random generator service.

Throws

\Exception

Initialization validation.

__destruct()

__destruct() 

Container destructor.

__clone()

__clone() 

Container cloning via deep copy.

seedRandomGenerator()

seedRandomGenerator(null|integer  $seed = null) : $this

Pass a seed value to the pseudo-randomness generator service.

Parameters

null|integer $seed

Seed value in integer format or null for auto-seeding.

Throws

\Exception

Validation errors and service misuse.

Returns

$this —

The container object.

setRandomGenerator()

setRandomGenerator(\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator  $generator) : $this

Setter for the pseudo-random generator service.

Parameters

\CryptoManana\Core\Abstractions\Randomness\AbstractGenerator $generator

The pseudo-random generator service.

Returns

$this —

The container object.

getTokenString()

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.

Parameters

integer $length

The desired output length (default => 32).

boolean|integer $useAlphaNumeric

Flag for switching to alphanumerical (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated alphanumeric/hexadecimal token string.

getPasswordString()

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.

Parameters

integer $length

The desired output length (default => 12).

boolean|integer $stronger

Flag for using all printable ASCII characters (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated password string.

getHashingKey()

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.

Parameters

integer $length

The desired output length (default => 16).

boolean|integer $printable

Flag for using only printable characters instead of bytes (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated HMAC key.

getHashingSalt()

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.

Parameters

integer $length

The desired output length (default => 16).

boolean|integer $printable

Flag for using only printable characters instead of bytes (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated hashing salt.

getEncryptionKey()

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.

Parameters

integer $length

The desired output length (default => 16).

boolean|integer $printable

Flag for using only printable characters instead of bytes (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated encryption key.

getEncryptionInitializationVector()

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.

Parameters

integer $length

The desired output length (default => 16).

boolean|integer $printable

Flag for using only printable characters instead of bytes (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated encryption initialization vector.

getAsymmetricKeyPair()

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.

Parameters

integer $keySize

The key size in bits.

integer $algorithmType

The asymmetric algorithm type integer code.

Throws

\Exception

Validation errors.

Returns

\CryptoManana\DataStructures\KeyPair

Randomly generated asymmetric key pair (private and public keys) as an object.

validateKeyPairSize()

validateKeyPairSize(integer  $keySize) 

Internal method for asymmetric algorithm type validation.

Parameters

integer $keySize

The key size in bits.

Throws

\Exception

Validation errors.

applyLengthValidation()

applyLengthValidation(integer  $length) 

Internal method for validation of positive output length.

Parameters

integer $length

The output length value for validation.

Throws

\Exception

Validation errors.

validateAsymmetricAlgorithmType()

validateAsymmetricAlgorithmType(integer  $algorithmType) 

Internal method for asymmetric algorithm type validation.

Parameters

integer $algorithmType

The asymmetric algorithm type integer code.

Throws

\Exception

Validation errors.

generatePrivateKey()

generatePrivateKey(integer  $keySize, string  $algorithmType) : resource

Internal method for generating a fresh private key pair of the given size and type.

Parameters

integer $keySize

The private key size in bits.

string $algorithmType

The asymmetric algorithm type.

Throws

\Exception

Validation or system errors.

Returns

resource —

The private key resource.

generatePublicKey()

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.

Parameters

integer $keySize

The private key size in bits.

resource $privateKeyResource

The private key resource.

Throws

\Exception

Validation or system errors.

Returns

string —

The extracted public key string.

getPasswordCharacter()

getPasswordCharacter(integer|mixed  $case) : string

Internal method for generation of characters used for secure password string building.

Parameters

integer|mixed $case

Generation case as integer.

Throws

\Exception

Validation Errors.

Returns

string —

Password character.