aes.js 865 Bytes
var Crypto = require('./cryptojs/cryptojs.js').Crypto;

module.exports = {
  Encrypt:Encrypt,
  Decrypt:Decrypt
}

/**
 * ECB模式的AES加密,偏移量为空
 */
function Encrypt (word){
    var mode = new Crypto.mode.ECB(Crypto.pad.pkcs7);
    var eb = Crypto.charenc.UTF8.stringToBytes(word);
    var kb = Crypto.charenc.UTF8.stringToBytes("yoho9646yoho9646");//KEY
    var vb = Crypto.charenc.UTF8.stringToBytes("0");//IV
    var ub = Crypto.AES.encrypt(eb,kb,{iv:vb,mode:mode,asBpytes:true});
    return ub;
	}

  function Decrypt (word){
    var mode = new Crypto.mode.ECB(Crypto.pad.pkcs7);
    var eb = Crypto.util.base64ToBytes(word);
    var kb = Crypto.charenc.UTF8.stringToBytes("yoho9646yoho9646");//KEY
    var vb = Crypto.charenc.UTF8.stringToBytes("0");//IV
    var ub = Crypto.AES.decrypt(eb,kb,{asBpytes:true,mode:mode,iv:vb});
    return ub;
}