-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathKeyGenerator.php
65 lines (57 loc) · 1.4 KB
/
KeyGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Query Auth: Signature generation and validation for REST API query authentication
*
* @copyright 2013-2014 Jeremy Kendall
* @license https://github.com/jeremykendall/query-auth/blob/master/LICENSE MIT
* @link https://github.com/jeremykendall/query-auth
*/
namespace QueryAuth;
use RandomLib\Generator;
/**
* Creates API keys and secrets
*/
class KeyGenerator
{
/**
* @var Generator RandomLib Generator
*/
private $generator;
/**
* Public constructor
*
* @param Generator $generator RandomLib generator
*/
public function __construct(Generator $generator)
{
$this->generator = $generator;
}
/**
* Returns 40 character alphanumeric random string
*
* @return string API key
*/
public function generateKey()
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return $this->generator->generateString(40, $chars);
}
/**
* Returns 60 character alphanumeric plus '.' and '/' random string
*
* @return string API secret
*/
public function generateSecret()
{
return $this->generator->generateString(60);
}
/**
* Returns 64 character alphanumeric plus '.' and '/' random string
*
* @return string Nonce
*/
public function generateNonce()
{
return $this->generator->generateString(64);
}
}