/** * Creates a salt * * @return string */ public static function createSalt() { $salt = Random::createString(self::SALT_START_LENGTH); $base64 = base64_encode($salt); $salt = self::convertAlphabets($base64); return Binary::getSlice($salt, 0, self::SALT_FINAL_LENGTH); }
/** * @param int $length * @return string|null */ public static function dev($length) { if (!is_readable('/dev/urandom')) { return null; } $fp = fopen('/dev/urandom', 'r'); $left = $length; $result = []; do { $buffer = fread($fp, $left); $lBuffer = Binary::getLength($buffer); if ($lBuffer === 0) { fclose($fp); return null; } $result[] = $buffer; $left -= $lBuffer; } while ($left > 0); fclose($fp); return implode('', $result); }
/** * Returns an array of bytes * * @param int $count * @return int[] */ public static function createBytes($count) { return Binary::unpackBytes(self::createString($count)); }
/** * @param string $a * @param string $b * @return string */ public static function plus($a, $b) { $a = Binary::getByteFromChar($a); $b = Binary::getByteFromChar($b); return chr($a + $b); }