function byteArrayToHex(b) {
var a = "";
if (b) {
for (var c = 0; c < b.length; c++)
a += (b[c] < 16 ? "0" : "") + b[c].toString(16);
return a
}
}
function getRandomBytes(b) {
var a, c = [];
for (a = 0; a < b; a++)
c[a] = Math.round(Math.random() * 255);
return c
}
function hex2s(b) {
var a = "";
if (b.indexOf("0x") == 0 || b.indexOf("0X") == 0)
b = b.substr(2);
if (b.length % 2)
b += "0";
for (var c = 0; c < b.length; c += 2)
a += String.fromCharCode(parseInt(b.slice(c, c + 2), 16));
return a
}
function formatPlaintext(b) {
var a = blockSizeInBits / 8, c;
if (typeof b == "string" || b.indexOf) {
b = b.split("");
for (c = 0; c < b.length; c++)
b[c] = b[c].charCodeAt(0) & 255
}
for (c = a - b.length % a; c > 0 && c < a; c--)
b[b.length] = 0;
return b
}
function rijndaelEncrypt(b, a, c) {
var d, e = blockSizeInBits / 8, f;
if (b && a)
if (a.length * 8 == keySizeInBits) {
if (c == "CBC")
f = getRandomBytes(e);
else {
c = "ECB";
f = []
}
b = formatPlaintext(b);
for (var h = new keyExpansion(a), g = 0; g < b.length / e; g++) {
d = b.slice(g * e, (g + 1) * e);
if (c == "CBC")
for (a = 0; a < e; a++)
d[a] ^= f[g * e + a];
f = f.concat(AESencrypt(d, h))
}
return f
}
}
var encryptRequest = function(
url) {
var key = "thesecretkey";
window.blockSizeInBits = 128;
window.keySizeInBits = key.length * 4;
var urlStart =
url.substring(0,
url.indexOf('?') + 1);
var queryString =
url.substring(
url.indexOf('?') + 1);
var queryToEncrypt = [];
var queryRest = [];
var queryStringToEncrypt = "";
var queryStringRest = "";
var params = queryString.split("&");
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (param.indexOf("MIKE=") == 0 || param.indexOf("HEINZ=") == 0 || param.indexOf("ULRIKE=") == 0 || param.indexOf("DELPHI=") == 0) {
queryStringRest += param + '&';
} else {
queryStringToEncrypt += param + '&';
}
}
var d = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 6E4);
var ENC_TIME = d.format("yyyymmddHHMMss");
queryStringToEncrypt += "&ENC_TIME=" + ENC_TIME;
var ENC = (byteArrayToHex(rijndaelEncrypt(queryStringToEncrypt, hex2s(key), "ECB")) + "").toUpperCase();
return urlStart + queryStringRest + "ENC="+ENC;
};