Authored by 王水玲

uid cookie 加密解密

... ... @@ -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
};
... ...
... ... @@ -56,7 +56,7 @@
"uuid": "^2.0.2",
"winston": "^2.2.0",
"winston-daily-rotate-file": "^1.1.4",
"yoho-node-lib": "0.0.21"
"yoho-node-lib": "0.0.22"
},
"devDependencies": {
"autoprefixer": "^6.3.6",
... ...