-
Notifications
You must be signed in to change notification settings - Fork 1
/
api-key.js
68 lines (62 loc) · 1.59 KB
/
api-key.js
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
66
67
/**
* Just a random key generator; No guarantee for a unique set
* @author Jiju TM <[email protected]>
* @repo jthoma/code-collection/node
*/
/**
* @const {array} char list
*/
const secret_salt = [
"a","b","c","d","e","f","g","h","i","j","k",
"l","m","n","o","p","q","r","s","t","u","v",
"w","x","y","z","0","1","2","3","4","5","6",
"7","8","9","A","B","C","D","E","F","G","H",
"I","J","K","L","M","N","O","P","Q","R","S",
"T","U","V","W","X","Y","Z","/","$","%","."
];
/**
* @const {array} char list upper case only
*/
const access_salt = [
"A","B","C","D","E","F","G","H","I","J","K",
"L","M","N","O","P","Q","R","S","T","U","V",
"W","X","Y","Z"
];
/**
* string genKey
* @description Returns random string from chars array with length
* @var {int} length
* @var {array} chars
* @return {string}
*/
function genKey(length, chars) {
if(length > 0) {
var rand_id = "";
for(var i = 0; i < length; i++) {
num = Math.floor(Math.random() * chars.length);
rand_id += chars[num];
}
}
return rand_id;
}
module.exports = {
/**
* string access_key
* @description preset with 20 chars from uppercase alphabets only ;) similar to AWS ACCESS_KEY_ID
*/
access_key: function(){
return genKey(20, access_salt);
},
/**
* string secret_key
* @description Preset with 40 chars from secret_salt, similar to AWS_SECRET_ACCESS_KEY
*/
secret_key: function(){
return genKey(40, secret_salt);
},
/**
* string any_key ( length, chars )
* @description Expose private function genKey for full flexibility
*/
any_key:genKey
}