/**
 * Created by MyPC on 2019/11/7.
 */
var crypto = require('crypto');
//加密
var hashEncode=function (id){//aes192
    var cipher = crypto.createCipher('aes192', CRYPTO_KEY);
    var enc = cipher.update(id, 'utf8', 'hex');
    enc += cipher.final('hex');
    return enc;
}
//解密
var hashDecode=function (id){
    var decipher = crypto.createDecipher('aes192', CRYPTO_KEY);
    var dec = decipher.update(id, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

//解密
var hashStaffDecode=function (id){
    var decipher = crypto.createDecipher('aes-256-ctr', CRYPTO_KEY);
    var dec = decipher.update(id, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

var isNotANumber=function(inputData){
    if (isNaN(inputData)) {
        return false;
    } else {
        return true;
    }
}

//是否存在或者为空
var isExistence=function (data){
    if(Array.isArray(data)){
        if(data.length==0){
            return false;
        }else{
            return true;
        }
    }else if(Object.prototype.toString.call(data) === '[object Object]'){
    	if (JSON.stringify(data) === '{}') {
    		return false ;
    	}else{
    		return true;
    	}
    }else if(data==''||data===null||typeof(data) == 'undefined'||data=='undefined'){
        return false;
    }else{
        return true;
    }
}


exports.hashDecode = hashDecode;
exports.hashEncode = hashEncode;
exports.hashStaffDecode = hashStaffDecode;
exports.isNotANumber = isNotANumber;
exports.isExistence = isExistence;


