mybase 1.0.38 → 1.0.39
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 +29 -0
- 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')
|
|
@@ -500,8 +501,36 @@ function int2ip (ipInt) {
|
|
|
500
501
|
function ip2int(ip) {
|
|
501
502
|
return ip.split('.').reduce(function(ipInt, octet) { return (ipInt<<8) + parseInt(octet, 10)}, 0) >>> 0;
|
|
502
503
|
}
|
|
504
|
+
function encryptAES_CBC_NOIV(plainString, encryptionKey) {
|
|
505
|
+
try {
|
|
506
|
+
const key = aesjs.utils.utf8.toBytes(encryptionKey); // 16,32 Bytes = 128,256 bits = AES128,AES256
|
|
507
|
+
const textBytes = aesjs.utils.utf8.toBytes(plainString);
|
|
508
|
+
const aesCbc = new aesjs.ModeOfOperation.cbc(key);
|
|
509
|
+
const encryptedBytes = aesCbc.encrypt(aesjs.padding.pkcs7.pad(textBytes, 16));
|
|
510
|
+
return aesjs.utils.hex.fromBytes(encryptedBytes);
|
|
511
|
+
} catch (err) {
|
|
512
|
+
// console.log(err)
|
|
513
|
+
return false
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function decryptAES_CBC_NOIV(encryptedHex, encryptionKey) {
|
|
518
|
+
try {
|
|
519
|
+
const key = aesjs.utils.utf8.toBytes(encryptionKey); // 16,32 Bytes = 128,256 bits = AES128,AES256
|
|
520
|
+
const encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
|
|
521
|
+
const aesCbc = new aesjs.ModeOfOperation.cbc(key);
|
|
522
|
+
const decryptedBytes = aesjs.padding.pkcs7.strip(aesCbc.decrypt(encryptedBytes));
|
|
523
|
+
return aesjs.utils.utf8.fromBytes(decryptedBytes);
|
|
524
|
+
|
|
525
|
+
} catch (err) {
|
|
526
|
+
// console.log(err)
|
|
527
|
+
return false
|
|
528
|
+
}
|
|
529
|
+
}
|
|
503
530
|
|
|
504
531
|
module.exports = {
|
|
532
|
+
encryptAES_CBC_NOIV,
|
|
533
|
+
decryptAES_CBC_NOIV,
|
|
505
534
|
ip2int,int2ip,
|
|
506
535
|
canReadAndWrite,
|
|
507
536
|
softexit,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mybase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
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",
|