|
|
/**
|
|
|
* 登录注册密码加密
|
|
|
* 登录注册密码加密,uid加密
|
|
|
* @author: wsl<shuiling.wang@yoho.cn>
|
|
|
* @date: 2016/07/07
|
|
|
*/
|
...
|
...
|
@@ -8,21 +8,63 @@ |
|
|
|
|
|
const crypto = require('crypto');
|
|
|
|
|
|
const aesPwd = (pwd) => {
|
|
|
let algorithm = 'aes-128-ecb';
|
|
|
let key = 'yoho9646yoho9646';
|
|
|
let clearEncoding = 'utf8';
|
|
|
let cipherEncoding = 'base64';
|
|
|
let iv = '';
|
|
|
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(pwd, clearEncoding, cipherEncoding));
|
|
|
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 (var i = 0; i < cipherChunks.length; i++) {
|
|
|
plainChunks.push(decipher.update(cipherChunks[i], cipherEncoding, clearEncoding));
|
|
|
}
|
|
|
|
|
|
plainChunks.push(decipher.final(clearEncoding));
|
|
|
|
|
|
return plainChunks.join('');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 登录密码加密
|
|
|
**/
|
|
|
const aesPwd = (pwd) => {
|
|
|
return _encryption('yoho9646yoho9646', pwd);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* uid加密
|
|
|
**/
|
|
|
const encryptionUid = (uid) => {
|
|
|
return _encryption('yoho9646abcdefgh', uid + '');
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* uid解密
|
|
|
**/
|
|
|
const DecryptUid = (uid) => {
|
|
|
return _decrypt('yoho9646abcdefgh', uid + '');
|
|
|
};
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
aesPwd
|
|
|
aesPwd,
|
|
|
encryptionUid,
|
|
|
DecryptUid
|
|
|
}; |
...
|
...
|
|