...
|
...
|
@@ -6,65 +6,23 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const crypto = require('crypto');
|
|
|
|
|
|
const algorithm = 'aes-128-ecb';
|
|
|
const clearEncoding = 'utf8';
|
|
|
const cipherEncoding = 'base64';
|
|
|
const iv = '';
|
|
|
|
|
|
// 加密
|
|
|
const _encryption = (keys, Keyword) => {
|
|
|
let key = keys ? keys : 'yoho9646abcdefgh';
|
|
|
let cipher = crypto.createCipheriv(algorithm, key, iv);
|
|
|
let cipherChunks = [];
|
|
|
|
|
|
cipherChunks.push(cipher.update(Keyword, clearEncoding, cipherEncoding));
|
|
|
cipherChunks.push(cipher.final(cipherEncoding));
|
|
|
|
|
|
return cipherChunks.join('');
|
|
|
};
|
|
|
|
|
|
// 解密
|
|
|
const _decrypt = (keys, Keyword) => {
|
|
|
let key = keys ? keys : 'yoho9646abcdefgh';
|
|
|
let decipher = crypto.createDecipheriv(algorithm, key, iv);
|
|
|
let plainChunks = [];
|
|
|
let cipherChunks = [Keyword];
|
|
|
|
|
|
for (let i = 0; i < cipherChunks.length; i++) {
|
|
|
plainChunks.push(decipher.update(cipherChunks[i], cipherEncoding, clearEncoding));
|
|
|
}
|
|
|
|
|
|
plainChunks.push(decipher.final(clearEncoding));
|
|
|
|
|
|
return plainChunks.join('');
|
|
|
};
|
|
|
const crypto = global.yoho.crypto;
|
|
|
|
|
|
/**
|
|
|
* 登录密码加密
|
|
|
* 密码加密
|
|
|
**/
|
|
|
const aesPwd = (pwd) => {
|
|
|
return _encryption('yoho9646yoho9646', pwd);
|
|
|
return crypto.encryption('yoho9646yoho9646', pwd);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* uid加密
|
|
|
**/
|
|
|
const encryptionUid = (uid) => {
|
|
|
return _encryption('yoho9646abcdefgh', uid + '');
|
|
|
return crypto.encryption('yoho9646abcdefgh', uid + '');
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* uid解密
|
|
|
**/
|
|
|
const DecryptUid = (uid) => {
|
|
|
return _decrypt('yoho9646abcdefgh', uid + '');
|
|
|
};
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
aesPwd,
|
|
|
encryptionUid,
|
|
|
DecryptUid
|
|
|
encryptionUid
|
|
|
}; |
...
|
...
|
|