Kodi Community Forum
Android Need help for Crypto AES - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Android Need help for Crypto AES (/showthread.php?tid=376707)



Need help for Crypto AES - sviet2k - 2024-03-20

Hi,

I would like to transport the following JS code  to Kodi Add-on Python.
I don't know which library I have to use for the PBKDF2 and decrypt with option KEY and IV.
Please guide me for this.

Thank you in advance.

JS Script:

    function CryptoJSAesDecrypt(passphrase, encrypted_json_string) {
        var obj_json = JSON.parse(encrypted_json_string);
        var encrypted = obj_json.ciphertext;
        var salt = CryptoJS.enc.Hex.parse(obj_json.salt);
        var iv = CryptoJS.enc.Hex.parse(obj_json.iv);
        var key = CryptoJS.PBKDF2(passphrase, salt, { hasher: CryptoJS.algo.SHA512, keySize: 64/8, iterations: 999});
        var decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv});
        return decrypted.toString(CryptoJS.enc.Utf8);
    }


RE: Need help for Crypto AES - doko-desuka - 2024-04-06

That looks complicated.

I have this module that I used in a personal add-on, it's for Python 2.7 and it's been tested to work on Kodi Leia 18.9. 
The code is from the SlowAES package on github (probably called that because it's implemented in pure Python):
SlowAES.py on PasteBin

With the passphrase, you need to use the "PBKDF2" algorithm to generate the key to decrypt the data with.
The PBKDF2 algorithm is explained in Wikipedia in here: https://en.wikipedia.org/wiki/PBKDF2#Key_derivation_process 
You can find someone's SHA512 implementation in Python in here: https://gist.github.com/illia-v/7883be942da5d416521375004cecb68f 

So it should take a lot of testing, tweaking etc. until you get it to work. 
If you get stuck and nobody's answering, try ChatGPT for assistance.


RE: Need help for Crypto AES - sviet2k - 2024-04-06

I will try it.
Thanks a lot doko-desuka


RE: Need help for Crypto AES - wsnipex - 2024-04-06

https://www.pycryptodome.org/ should do what you want, kodi ships this already. You can import it in your addon:
<import addon="script.module.pycryptodome" version="3.4.3"/>


RE: Need help for Crypto AES - sviet2k - 2024-04-06

(2024-04-06, 10:27)wsnipex Wrote: https://www.pycryptodome.org/ should do what you want, kodi ships this already. You can import it in your addon:
<import addon="script.module.pycryptodome" version="3.4.3"/>

Thanks wsnipex