Android Need help for Crypto AES
#1
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);
    }
Reply
#2
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...on_process 
You can find someone's SHA512 implementation in Python in here: https://gist.github.com/illia-v/7883be94...004cecb68f 

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.
Reply
#3
I will try it.
Thanks a lot doko-desuka
Reply
#4
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"/>
Reply
#5
(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
Reply

Logout Mark Read Team Forum Stats Members Help
Need help for Crypto AES0