mybase 1.0.38 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/mybase.js +48 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -36,6 +36,10 @@ var { isLocal } = require('mybase')
|
|
|
36
36
|
|
|
37
37
|
### arrayRandomItem(array,defaultValue=false)
|
|
38
38
|
### maxmindOpen(geoipFile) : <Promise>
|
|
39
|
+
|
|
40
|
+
## Encryption
|
|
41
|
+
### decryptAES_CBC_NOIV(encryptedHex, encryptionKey)
|
|
42
|
+
### encryptAES_CBC_NOIV(plainString, encryptionKey)
|
|
39
43
|
```
|
|
40
44
|
var handle = await maxmindOpen(config.geoip.country)
|
|
41
45
|
```
|
package/mybase.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const aesjs = require("aes-js")
|
|
1
2
|
const debug = require('debug')('mybase')
|
|
2
3
|
const os = require('os')
|
|
3
4
|
const fs = require('fs')
|
|
@@ -446,6 +447,22 @@ function validUUID4(uuid) {
|
|
|
446
447
|
return new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i).test(uuid)
|
|
447
448
|
}
|
|
448
449
|
|
|
450
|
+
function promiseTimeout(ms, promise) {
|
|
451
|
+
// Create a promise that rejects in <ms> milliseconds
|
|
452
|
+
let timeout = new Promise((resolve, reject) => {
|
|
453
|
+
let id = setTimeout(() => {
|
|
454
|
+
clearTimeout(id);
|
|
455
|
+
reject('TIMEDOUT')
|
|
456
|
+
}, ms)
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
// Returns a race between our timeout and the passed in promise
|
|
460
|
+
return Promise.race([
|
|
461
|
+
promise,
|
|
462
|
+
timeout
|
|
463
|
+
])
|
|
464
|
+
}
|
|
465
|
+
|
|
449
466
|
async function portCheck_tcp (port, {timeout = 1000, host='127.0.0.1'} = {}) {
|
|
450
467
|
const promise = new Promise(((resolve, reject) => {
|
|
451
468
|
const socket = new net.Socket();
|
|
@@ -500,8 +517,36 @@ function int2ip (ipInt) {
|
|
|
500
517
|
function ip2int(ip) {
|
|
501
518
|
return ip.split('.').reduce(function(ipInt, octet) { return (ipInt<<8) + parseInt(octet, 10)}, 0) >>> 0;
|
|
502
519
|
}
|
|
520
|
+
function encryptAES_CBC_NOIV(plainString, encryptionKey) {
|
|
521
|
+
try {
|
|
522
|
+
const key = aesjs.utils.utf8.toBytes(encryptionKey); // 16,32 Bytes = 128,256 bits = AES128,AES256
|
|
523
|
+
const textBytes = aesjs.utils.utf8.toBytes(plainString);
|
|
524
|
+
const aesCbc = new aesjs.ModeOfOperation.cbc(key);
|
|
525
|
+
const encryptedBytes = aesCbc.encrypt(aesjs.padding.pkcs7.pad(textBytes, 16));
|
|
526
|
+
return aesjs.utils.hex.fromBytes(encryptedBytes);
|
|
527
|
+
} catch (err) {
|
|
528
|
+
// console.log(err)
|
|
529
|
+
return false
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function decryptAES_CBC_NOIV(encryptedHex, encryptionKey) {
|
|
534
|
+
try {
|
|
535
|
+
const key = aesjs.utils.utf8.toBytes(encryptionKey); // 16,32 Bytes = 128,256 bits = AES128,AES256
|
|
536
|
+
const encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
|
|
537
|
+
const aesCbc = new aesjs.ModeOfOperation.cbc(key);
|
|
538
|
+
const decryptedBytes = aesjs.padding.pkcs7.strip(aesCbc.decrypt(encryptedBytes));
|
|
539
|
+
return aesjs.utils.utf8.fromBytes(decryptedBytes);
|
|
540
|
+
|
|
541
|
+
} catch (err) {
|
|
542
|
+
// console.log(err)
|
|
543
|
+
return false
|
|
544
|
+
}
|
|
545
|
+
}
|
|
503
546
|
|
|
504
547
|
module.exports = {
|
|
548
|
+
encryptAES_CBC_NOIV,
|
|
549
|
+
decryptAES_CBC_NOIV,
|
|
505
550
|
ip2int,int2ip,
|
|
506
551
|
canReadAndWrite,
|
|
507
552
|
softexit,
|
|
@@ -534,5 +579,7 @@ module.exports = {
|
|
|
534
579
|
portCheck_tcp,
|
|
535
580
|
asJSON,
|
|
536
581
|
ensureProperty,
|
|
537
|
-
arrayRandomItem
|
|
582
|
+
arrayRandomItem,
|
|
583
|
+
promiseTimeout
|
|
584
|
+
|
|
538
585
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mybase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mybase.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@7c/validurl": "0.0.3",
|
|
13
|
+
"aes-js": "^3.1.2",
|
|
13
14
|
"chalk": "^3.0.0",
|
|
14
15
|
"debug": "^4.3.1",
|
|
15
16
|
"punycode": "^2.1.1",
|