/** * Tests getting a random hexadecimal string. * * @covers empire\framework\util\Math::getRandomHexString */ public function testGetRandomHexString() { $length = mt_rand(1, 20); $res = Math::getRandomHexString($length); $this->assertTrue(strlen($res) === $length); $this->assertTrue(hex2bin($res) !== false); }
/** * Returns a session ID. * * @return string the session ID */ private function createSID() { return Math::getRandomHexString(64); }
public function calculatePasswordHash($password, $iterations, $hmacKey) { // Calculate salt $salt = Math::getRandomHexString(static::BCRYPT_SALT_LENGTH); $salt = $this->buildCryptSalt($salt, $iterations); // Calculate bcrypt $hash = crypt($password, $salt); // Build return string $args = base64_encode($hash) . self::SEGMENT_SEPARATOR . base64_encode($salt); $hmac = $this->calculateHMAC($args, $hmacKey); return $args . self::SEGMENT_SEPARATOR . base64_encode($hmac); }
public function createKey() { return pack('H*', Math::getRandomHexString($this->getKeySize())); }