//#import Util.js

var owlDigestUtilApi = new JavaImporter(
    Packages.net.xinshi.isone.commons
);

var OwlDigestUtil = (function () {
    var key = '1jkc03,dy2l,xk55';
    var f = {
        decrypt: function (data, key, iv) {
            if (iv.length >= 16) {
                iv = iv.substring(0, 16);
            }
            else {
                iv = "0000000000000000";
            }
            return "" + owlDigestUtilApi.AESEncryptUtil.decrypt(data, key, iv);
        },
        getParamsByBody: function (body) {
            if(body) {
                var encryptedParams = JSON.parse(body);
                var isid = encryptedParams.isid;
                if(encryptedParams.e){
                    var plainText = f.decrypt(encryptedParams.e, key, isid);
                    $.log("plainText=" + plainText);
                    var params =  JSON.parse(plainText);
                    params.isid = isid;
                    return params;
                }
            }
            return null;
        }
    };
    return f;
})();