Convert Python to Xojo

  1. 6 weeks ago

    Raimund P

    May 31 Testers, Xojo Pro Austria
    Edited 6 weeks ago

    Perhaps there is a python- & xojo-pro out there who simply can convert some python-lines to xojo?!

    Python Code

    from Crypto.Cipher import AES
    from binascii import unhexlify
    from Crypto.Protocol.KDF import PBKDF2
    import base64
    
    DDK = 'DDK-String'
    secret = PBKDF2(DDK, unhexlify(DDK), 16, 1000, None)
    IV = unhexlify(DDK)
    decipher = AES.new(secret, AES.MODE_CBC, IV)
    decrypted = decipher.decrypt(base64.b64decode('encrypted token')).decode('utf-8')
    token = decrypted[:36]

    To Xojo Code, the first try, but no idea if it's right and how to continue

    Dim strEncryptedText As String
    Dim strKey As String = "123456789..."
    Dim strIV As String = DecodeHex(strKey)
    Dim hash As MemoryBlock
    hash = Crypto.PBKDF2(strKey, DecodeHex(strEncryptedText), 1000, 16, crypto.HashAlgorithms.SHA256)

    Ideas like this, but no solution yet ...
    DecodeBase64()
    ConvertEncoding(DecodeBase64(strEncryptedText), Encodings.UTF8)
    Dim a as AESMBS
    a.EncryptCBC ...

  2. Eugene D

    Jun 2 Testers, Xojo Pro Canada scispec.ca

    Hello Raimund,

    I believe you are on the correct path to convert the Python code to Xojo. Although libraries between languages are close, sometimes they are not close enough. In the past I found that I had to rewrite portions of the Python AES library to use the functions in Xojo. This way I knew that the two libraries and the files/data that was being sent and received worked flawlessly.

    Try the built-in Xojo functions and see if they work, and if not you may need to rewrite some libraries. If your not in a rush, rewriting libraries helps learn the internal functions and algorithms. :)

  3. Raimund P

    Jun 3 Testers, Xojo Pro Austria

    Thank you for reply Eugene.

    I had the same thought as you :) but time is always a big problem. I am sure I would find a solution if I had an hour or two to think about it and write it. I was just hoping a Python pro would see that and have the solution in a second :D

    For now I made a workaround in PHP, that worked in minutes, but don't makes me that happy, because it's PHP and not XOJO :D

  4. Erwin M

    Jun 3 Testers, Xojo Pro Netherlands
    Edited 6 weeks ago

    Check Chilkat plug-inn ...https://www.example-code.com/xojo/default.asp

  5. Raimund P

    Jun 3 Testers, Xojo Pro Austria

    Thank you Erwin, I'll take a look at it when I'm building the imap client, I think Chillcat has the best working solution for imap and perhaps there's also a solution for the above conversion. :)

or Sign Up to reply!