yanxxit-reskit
Version:
1 lines • 1.34 kB
JavaScript
;var crypto=require("crypto"),moment=require("moment");exports.aesEncrypt=function(e,r){try{var t=crypto.createCipher("aes-128-ecb",r),e=t.update(e,"utf8","hex")+t.final("hex");return e}catch(e){return console.error("加密时异常"+e),""}},exports.aesDecrypt=function(e,r){try{var t=crypto.createDecipher("aes-128-ecb",r),e=t.update(e,"hex","utf8")+t.final("utf8");return e}catch(e){return console.error("解密时异常"+e),""}},exports.md5=function(e){return crypto.createHash("md5").update(e).digest("hex")};var iv="mohoo-telecom-wx";exports.phpEncrypt=function(e,r){try{var t=crypto.createHash("md5").update(r).digest("hex"),c=crypto.createCipheriv("aes-256-cbc",t,iv);return c.update(e,"binary","base64")+c.final("base64")}catch(e){return console.error("加密时异常"+e),""}},exports.phpDecrypt=function(e,r){try{var t=crypto.createHash("md5").update(r).digest("hex"),c=crypto.createDecipheriv("aes-256-cbc",t,iv);return c.update(e,"base64","binary")+c.final("binary")}catch(e){return console.error("解密时异常"+e),""}},exports.tool_Encrypt=function(e,r){var t="",c=moment().unix();return r+=c,t=exports.aesEncrypt(e,r),t+=c},exports.tool_Decrypt=function(e,r){var t="",c=e.substr(e.length-10),o=e.substr(0,e.length-10),n=moment(1e3*c);return moment().diff(n,"seconds")>60?t:(r+=c,t=exports.aesDecrypt(o,r))};