RandomLib
=========
[![Build Status](https://travis-ci.org/ircmaxell/RandomLib.svg?branch=master)](https://travis-ci.org/ircmaxell/RandomLib)
A library for generating random numbers and strings of various strengths.
This library is useful in security contexts.
Install
-------
Via Composer
```sh
$ composer require ircmaxell/random-lib
```
Usage
-----
### Factory
A factory is used to get generators of varying strength:
```php
$factory = new RandomLib\Factory;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
```
A factory can be configured with additional mixers and sources but can be
used out of the box to create both medium and low strength generators.
Convenience methods are provided for creating high, medium, and low
strength generators. Example:
```php
$generator = $factory->getMediumStrengthGenerator();
```
#### $factory->getLowStrengthGenerator()
Convenience method to get a low strength random number generator.
Low Strength should be used anywhere that random strings are needed in a
non-cryptographical setting. They are not strong enough to be used as
keys or salts. They are however useful for one-time use tokens.
#### $factory->getMediumStrengthGenerator()
Convenience method to get a medium strength random number generator.
Medium Strength should be used for most needs of a cryptographic nature.
They are strong enough to be used as keys and salts. However, they do
take some time and resources to generate, so they should not be over-used
#### $factory->getHighStrengthGenerator()
Convenience method to get a high strength random number generator.
High Strength keys should ONLY be used for generating extremely strong
cryptographic keys. Generating them is very resource intensive and may
take several minutes or more depending on the requested size.
**There are currently no mixers shipped with this package that are
capable of creating a high space generator. This will not work out of
the box!**
### Generator
A generator is used to generate random numbers and strings.
Example:
```php
// Generate a random string that is 32 bytes in length.
$bytes = $generator->generate(32);
// Generate a whole number between 5 and 15.
$randomInt = $generator->generateInt(5, 15);
// Generate a 32 character string that only contains the letters
// 'a', 'b', 'c', 'd', 'e', and 'f'.
$randomString = $generator->generateString(32, 'abcdef');
```
#### $generator->generate($size)
Generate a random byte string of the requested size.
#### $generator->generateInt($min = 0, $max = PHP_INT_MAX)
Generate a random integer with the given range. If range (`$max - $min`)
is zero, `$max` will be used.
#### $generator->generateString($length, $characters = '')
Generate a random string of specified length.
This uses the supplied character list for generating the new result
string. The list of characters should be specified as a string containing
each allowed character.
If no character list is specified, the following list of characters is used:
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/
**Examples:**
```php
// Give the character list 'abcdef':
print $generator->generateString(32, 'abcdef')."\n";
// One would expect to receive output that only contained those
// characters:
//
// adaeabecfbddcdaeedaedfbbcdccccfe
// adfbfdbfddadbfcbbefebcacbefafffa
// ceeadbcabecbccacdcaabbdccfadbafe
// abadcffabdcacdbcbafcaecabafcdbbf
// dbdbddacdeaceabfaefcbfafebcacdca
```
License
-------
MIT, see LICENSE.
Community
---------
If you have questions or want to help out, join us in the **#php.security**
channel on **irc.freenode.net**.
Security Vulnerabilities
========================
If you have found a security issue, please contact the author directly at [me@ircmaxell.com](mailto:me@ircmaxell.com).
没有合适的资源?快使用搜索试试~ 我知道了~
[示例][PHP]RandomLib-master生成随机数和随机字符串的PHP库.zip
共48个文件
php:39个
yml:2个
gitignore:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 38 浏览量
2021-12-15
14:30:54
上传
评论
收藏 49KB ZIP 举报
温馨提示
通常情况下,当我们要生成一个随机字符串时,总是先创建一个字符池,然后用一个循环和mt_rand()或rand()生成php随机数,从字符池中随机选取字符,最后拼凑出需要的长度。RandomLib-master生成随机数和随机字符串的PHP库就是这么一个工具。
资源详情
资源评论
资源推荐
收起资源包目录
[示例][PHP]RandomLib-master生成随机数和随机字符串的PHP库.zip (48个子文件)
RandomLib-master
composer.json 900B
.travis.yml 791B
.scrutinizer.yml 3KB
test
bootstrap.php 2KB
Unit
RandomLib
GeneratorTest.php 5KB
GeneratorStringTest.php 4KB
Source
MicroTimeTest.php 896B
SodiumTest.php 2KB
MTRandTest.php 628B
UniqIDTest.php 514B
RandTest.php 627B
CAPICOMTest.php 518B
AbstractSourceTest.php 2KB
URandomTest.php 518B
FactoryTest.php 2KB
Mixer
McryptRijndael128Test.php 2KB
HashTest.php 2KB
Vectors
Random
GeneratorTest.php 6KB
Mocks
Random
Source.php 2KB
Mixer.php 2KB
Generator.php 2KB
AbstractMock.php 1KB
.php_cs 2KB
LICENSE 1KB
.gitignore 21B
lib
RandomLib
AbstractMixer.php 4KB
Factory.php 7KB
AbstractSource.php 2KB
AbstractMcryptMixer.php 4KB
Source.php 2KB
Mixer.php 2KB
Generator.php 10KB
Source
OpenSSL.php 4KB
RandomBytes.php 2KB
Rand.php 2KB
MicroTime.php 4KB
CAPICOM.php 2KB
URandom.php 2KB
MTRand.php 2KB
UniqID.php 2KB
Sodium.php 3KB
Random.php 1KB
Mixer
XorMixer.php 3KB
Hash.php 3KB
McryptRijndael128.php 1KB
Makefile 317B
phpunit.xml.dist 939B
README.md 4KB
共 48 条
- 1
神仙别闹
- 粉丝: 2674
- 资源: 7640
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 嵌入式基础学习资料0000
- content_1714465331721.xls
- HM3401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Chainbase+Web3+APi+Data warehouse
- HM3401D-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- GEE案例-1990-2023年计算某个区域的NDVI时序变化轨迹(以徐州市为例)含全部代码.pdf
- HM3401C-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 沈丘盛世龙门图纸符合规范化
- 基于51单片机带LCD1602显示+温度补偿的超声波测距仪设计软硬设计+仿真+文档资料.zip
- 一、K210是什么? K210全称为堪智K210,是嘉楠科技自主研发的一款采用RISC-V处理器架构,具备视听一体、自主IP内核
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0