javascriptaesinitialization-vector

Decrypt AES with key and IV not producing useful output


I have the next json file. It includes an AES cyphered text. I have the key ITP2021ATP! and the way to generate the IV, but when i try to decrypt it, it is not working. It is base 64 encoded too.

var Ou = function(t) {
        var e = function(t) {
            var e = (new Date).getTimezoneOffset()
              , n = new Date(t.getTime() + 60 * e * 1e3).getDate()
              , r = parseInt((n < 10 ? "0" + n : n).toString().split("").reverse().join(""))
              , i = t.getFullYear()
              , a = parseInt(i.toString().split("").reverse().join(""))
              , o = parseInt(t.getTime().toString(), 16).toString(36) + ((i + a) * (n + r)).toString(24)
              , s = o.length;
            if (s < 14)
                for (var c = 0; c < 14 - s; c++)
                    o += "0";
            else
                s > 14 && (o = o.substr(0, 14));
            return "#" + o + "$"
        }(new Date(t.lastModified))
          , n = Jo.a.enc.Utf8.parse(e)
          , r = Jo.a.enc.Utf8.parse(e.toUpperCase())
          , i = Jo.a.AES.decrypt(t.response, n, {
            iv: r,
            mode: Jo.a.mode.CBC,
            padding: Jo.a.pad.Pkcs7
        });
        return JSON.parse(i.toString(Jo.a.enc.Utf8))
    };


{"lastModified":1666642401166,"response":"MCiQxX4X6Ul1myrY1nOq45F63b1vo2dkbQsbMKAodQIuRMVcrrI4x9I1+6Oh6+3RCd4GIYd4HZYMPz7ANXkkfACKTPR/fViIFo2nDloUiY8gRi+tMWyDUKKBxoIFreJuvQldLLPishC7KTpJ4X7lUI+L2it5U6+Qx/YaXKeMOOetMoX7hCF3QhEJ7vIm63g16Vyyq6b+qiMeFyCavdoLZ5GBVEBNboOKhLiCWSQzUZIg4FJ7nk3vJEY3p2NGiB/KTCYQjdFlMMLr+chwzV+AleLpOlAknJRuANqSLUOe5H75t4wnHn4xSZ6VpWhGD70xUfS50WmHwgGEs7XZ+onSCanzVoN+98eDT84mmBqAZJ6RwHFU0z9LJNG6vSKHDPhA4C5OHAOL53K4MzfpZkpybbC4ux+pxq/qoOCm6fAQYyOXgA1r3SY/QN5Mp2JzisZ0uhEhX11weqYgg96s5R2zL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R5aqAKJJtPRFQrbG4Y51gwS81h7p1CUxwUInvEmV3I7DgT7Bl9BZQ4FIHhYCfKIItv7X9eUe1a4YFPePBB2h9P6fKlLXtDvFjSFU/F55qKjoUy8z1OYlWizKw/FRCEqNoQ/ajClA2BAt4riZNPJUzcDi3/SmKNAjRAiE+HouSwJLLVhb/azBUIOsOUrdQNX6A8e+gYXWmZM4wRKIcgOvYLsZ2CBegj4TC1VIhq2dYFulCzAL7pBVYqFlbHsfmE0z3DPqnQZMgrxrtQSsel1hl2btHl+G+k6k/rIUtiErcY9TQp/8RpDrfPo6hey9V2/xhM/vp1508gL0FUPL7syExHlwEAh6+0f2zQBwG6DzjJinQznSJO416HvoSatfwu8MBxVOy3LeQLxuHCUj1CyQcbYSoxPwmALzmFYnj9UTwlx9tZlSgFgb+EK37bzEKlkJSZZL2Wy/42K1+qz6QFPoXcz8wz0EhT2FfJy8zGAyeS+pgSoPH0iZpwhItgUp5bQ9MPqCcG2/tn+yciopW0+0c/9ZNa1w8NZc8kvqNZbYPOjqx54m7Ki//hz85LAFi5b/7U7DkMDuTX/bR2YQ8wzO8onWAr+Zz34jOi5lzVDogTdzpYmo0RCRRPGtInKwc7vhKc+pqArPqLHEe2AGfEad+iMP4YVeCJDpGsjBsaxbYLYkEwi4HfqfFLgwVcQorb9/L3h6aRJ+8BRKtpAqq3J83nPhtXfu/ZQxWTOckWbvGgqQPnfkzd7yJidy99CZZLMSSubQ="}

But when I try to decrypt the file (must generate another json file) I dont get anything useful.

What am i doing wrong?

The IV generated for this based in modified json field is: #3VOMO21HLYK400$

I'm trying to understand what am i doing wrong but I dont get it. Any tip is welcomed.


Solution

  • The part:

    i = Jo.a.AES.decrypt(t.response, n, {iv: r, mode: Jo.a.mode.CBC, padding: Jo.a.pad.Pkcs7}
    ...
    return JSON.parse(i.toString(Jo.a.enc.Utf8))
    

    seems to use CryptoJS and performs a decryption with CBC and PKCS#7 padding.

    The function at the beginning appears to be a key derivation function, which derives the key presumably from a date as input. So for a reproduction of the key the input is needed. The meaning of ITP2021ATP! is not clear, it fits neither as input for the key derivation nor as key for the encryption. But even without the original input it is possible to derive the key if the IV is known, because there is a relation between key and IV.

    The parameter o in the key derivation contains a string, for the generation of which toString(36) and toString(24) was used. toString() applies lowercase letters for a radix larger than 10.
    o is extended to the key material e by adding digits and special characters, i.e. the key material consists of lowercase letters (plus digits and special characters).

    From the decryption part it can be deduced that n is the key and r is the IV, both of which are derived from the key material e as follows:

    n = CryptoJS.enc.Utf8.parse(e)
    r = CryptoJS.enc.Utf8.parse(e.toUpperCase())
    

    I.e. IV and key are identical and differ only in that lowercase letters are used for the key and uppercase letters for the IV.

    Since the IV is known #3VOMO21HLYK400$, the key can thus be easily derived by converting the uppercase letters to lowercase letters: #3vomo21hlyk400$.

    This allows the ciphertext to be decrypted with CryptoJS:

    var key = CryptoJS.enc.Utf8.parse('#3vomo21hlyk400$')
    var iv = CryptoJS.enc.Utf8.parse('#3VOMO21HLYK400$')
    var ciphertext = 'MCiQxX4X6Ul1myrY1nOq45F63b1vo2dkbQsbMKAodQIuRMVcrrI4x9I1+6Oh6+3RCd4GIYd4HZYMPz7ANXkkfACKTPR/fViIFo2nDloUiY8gRi+tMWyDUKKBxoIFreJuvQldLLPishC7KTpJ4X7lUI+L2it5U6+Qx/YaXKeMOOetMoX7hCF3QhEJ7vIm63g16Vyyq6b+qiMeFyCavdoLZ5GBVEBNboOKhLiCWSQzUZIg4FJ7nk3vJEY3p2NGiB/KTCYQjdFlMMLr+chwzV+AleLpOlAknJRuANqSLUOe5H75t4wnHn4xSZ6VpWhGD70xUfS50WmHwgGEs7XZ+onSCanzVoN+98eDT84mmBqAZJ6RwHFU0z9LJNG6vSKHDPhA4C5OHAOL53K4MzfpZkpybbC4ux+pxq/qoOCm6fAQYyOXgA1r3SY/QN5Mp2JzisZ0uhEhX11weqYgg96s5R2zL6bdJ4CzJOHAS3lIz6+yXxRpv4+5rjtyPyyD+IIBiA/vYnjLxurAngjjBgg6BFq1hPd2y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9eUe1a4YFPePBB2h9P6fKlLXtDvFjSFU/F55qKjoUy8z1OYlWizKw/FRCEqNoQ/ajClA2BAt4riZNPJUzcDi3/SmKNAjRAiE+HouSwJLLVhb/azBUIOsOUrdQNX6A8e+gYXWmZM4wRKIcgOvYLsZ2CBegj4TC1VIhq2dYFulCzAL7pBVYqFlbHsfmE0z3DPqnQZMgrxrtQSsel1hl2btHl+G+k6k/rIUtiErcY9TQp/8RpDrfPo6hey9V2/xhM/vp1508gL0FUPL7syExHlwEAh6+0f2zQBwG6DzjJinQznSJO416HvoSatfwu8MBxVOy3LeQLxuHCUj1CyQcbYSoxPwmALzmFYnj9UTwlx9tZlSgFgb+EK37bzEKlkJSZZL2Wy/42K1+qz6QFPoXcz8wz0EhT2FfJy8zGAyeS+pgSoPH0iZpwhItgUp5bQ9MPqCcG2/tn+yciopW0+0c/9ZNa1w8NZc8kvqNZbYPOjqx54m7Ki//hz85LAFi5b/7U7DkMDuTX/bR2YQ8wzO8onWAr+Zz34jOi5lzVDogTdzpYmo0RCRRPGtInKwc7vhKc+pqArPqLHEe2AGfEad+iMP4YVeCJDpGsjBsaxbYLYkEwi4HfqfFLgwVcQorb9/L3h6aRJ+8BRKtpAqq3J83nPhtXfu/ZQxWTOckWbvGgqQPnfkzd7yJidy99CZZLMSSubQ=';
    var decrypted = CryptoJS.AES.decrypt(
        ciphertext, 
        key, 
        {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        }
    );
    document.getElementById("dt").innerHTML = "Decrypted: " + decrypted.toString(CryptoJS.enc.Utf8);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
    <p style="font-family:'Courier New', monospace;" id="dt"></p>

    or e.g. on CyberChef: