|
@@ -6,65 +6,23 @@ |
|
@@ -6,65 +6,23 @@ |
6
|
|
6
|
|
7
|
'use strict';
|
7
|
'use strict';
|
8
|
|
8
|
|
9
|
-const crypto = require('crypto');
|
|
|
10
|
-
|
|
|
11
|
-const algorithm = 'aes-128-ecb';
|
|
|
12
|
-const clearEncoding = 'utf8';
|
|
|
13
|
-const cipherEncoding = 'base64';
|
|
|
14
|
-const iv = '';
|
|
|
15
|
-
|
|
|
16
|
-// 加密
|
|
|
17
|
-const _encryption = (keys, Keyword) => {
|
|
|
18
|
- let key = keys ? keys : 'yoho9646abcdefgh';
|
|
|
19
|
- let cipher = crypto.createCipheriv(algorithm, key, iv);
|
|
|
20
|
- let cipherChunks = [];
|
|
|
21
|
-
|
|
|
22
|
- cipherChunks.push(cipher.update(Keyword, clearEncoding, cipherEncoding));
|
|
|
23
|
- cipherChunks.push(cipher.final(cipherEncoding));
|
|
|
24
|
-
|
|
|
25
|
- return cipherChunks.join('');
|
|
|
26
|
-};
|
|
|
27
|
-
|
|
|
28
|
-// 解密
|
|
|
29
|
-const _decrypt = (keys, Keyword) => {
|
|
|
30
|
- let key = keys ? keys : 'yoho9646abcdefgh';
|
|
|
31
|
- let decipher = crypto.createDecipheriv(algorithm, key, iv);
|
|
|
32
|
- let plainChunks = [];
|
|
|
33
|
- let cipherChunks = [Keyword];
|
|
|
34
|
-
|
|
|
35
|
- for (let i = 0; i < cipherChunks.length; i++) {
|
|
|
36
|
- plainChunks.push(decipher.update(cipherChunks[i], cipherEncoding, clearEncoding));
|
|
|
37
|
- }
|
|
|
38
|
-
|
|
|
39
|
- plainChunks.push(decipher.final(clearEncoding));
|
|
|
40
|
-
|
|
|
41
|
- return plainChunks.join('');
|
|
|
42
|
-};
|
9
|
+const crypto = global.yoho.crypto;
|
43
|
|
10
|
|
44
|
/**
|
11
|
/**
|
45
|
- * 登录密码加密
|
12
|
+ * 密码加密
|
46
|
**/
|
13
|
**/
|
47
|
const aesPwd = (pwd) => {
|
14
|
const aesPwd = (pwd) => {
|
48
|
- return _encryption('yoho9646yoho9646', pwd);
|
15
|
+ return crypto.encryption('yoho9646yoho9646', pwd);
|
49
|
};
|
16
|
};
|
50
|
|
17
|
|
51
|
/**
|
18
|
/**
|
52
|
* uid加密
|
19
|
* uid加密
|
53
|
**/
|
20
|
**/
|
54
|
const encryptionUid = (uid) => {
|
21
|
const encryptionUid = (uid) => {
|
55
|
- return _encryption('yoho9646abcdefgh', uid + '');
|
22
|
+ return crypto.encryption('yoho9646abcdefgh', uid + '');
|
56
|
};
|
23
|
};
|
57
|
|
24
|
|
58
|
-/**
|
|
|
59
|
- * uid解密
|
|
|
60
|
- **/
|
|
|
61
|
-const DecryptUid = (uid) => {
|
|
|
62
|
- return _decrypt('yoho9646abcdefgh', uid + '');
|
|
|
63
|
-};
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
module.exports = {
|
25
|
module.exports = {
|
67
|
aesPwd,
|
26
|
aesPwd,
|
68
|
- encryptionUid,
|
|
|
69
|
- DecryptUid
|
27
|
+ encryptionUid
|
70
|
}; |
28
|
}; |