mybase 1.0.37 → 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 +32 -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')
|
|
@@ -23,7 +24,9 @@ function validHPassword(hpassword) { return (hpassword && hpassword.length === 1
|
|
|
23
24
|
function validEmail_old(email) { return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) }
|
|
24
25
|
|
|
25
26
|
function validEmail(email) {
|
|
26
|
-
|
|
27
|
+
if (typeof email==='string')
|
|
28
|
+
return validator.isEmail(email) // validator needs a string
|
|
29
|
+
return false
|
|
27
30
|
// giving up old style, was not reliable
|
|
28
31
|
// taken from https://www.w3resource.com/javascript/form/email-validation.php
|
|
29
32
|
// strange looking emails might be indeed valid
|
|
@@ -498,8 +501,36 @@ function int2ip (ipInt) {
|
|
|
498
501
|
function ip2int(ip) {
|
|
499
502
|
return ip.split('.').reduce(function(ipInt, octet) { return (ipInt<<8) + parseInt(octet, 10)}, 0) >>> 0;
|
|
500
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
|
+
}
|
|
501
530
|
|
|
502
531
|
module.exports = {
|
|
532
|
+
encryptAES_CBC_NOIV,
|
|
533
|
+
decryptAES_CBC_NOIV,
|
|
503
534
|
ip2int,int2ip,
|
|
504
535
|
canReadAndWrite,
|
|
505
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",
|