#1 Re: mORMot 1 » SynCrypto CFB/python » 2018-04-16 12:18:11

Hello,

I was able to decrypt (delphi) TAESCFB using MODE_OFB in python.

#3 Re: mORMot 1 » SynCrypto CFB/python » 2018-04-12 11:32:25

Yes,

CBC mode works fine both in python and delphi code.

#4 Re: mORMot 1 » SynCrypto CFB/python » 2018-04-11 18:32:53

Hello,

thanks for answering, i have double checked, the return from makekey function is already an array of bytes.

I have tried declaring it directly as:

key = b'\xBE\x31\xFB\x56\x2C\xFA\xED\x2B\x2E\xBF\x40\x57\x47\xE0\x77\x87\x5E\xE3\x00\xCE\x5B\x6C\xEF\x45\xEE\x5D\x3C\x39\xED\xB0\x41\x62'

but i got the same result, this is the key from delphi perspective. i have compared both and they match

keydelphi.png


this is the iv:

iv = b'\xB3\x73\xBC\xD6\xBF\xF0\x41\x73\x17\x02\x15\x51\xB1\x09\x18\x43'

which from delphi perspective is:

ivdelphi.png

this is the python snippted simplified:
    key = b'\xBE\x31\xFB\x56\x2C\xFA\xED\x2B\x2E\xBF\x40\x57\x47\xE0\x77\x87\x5E\xE3\x00\xCE\x5B\x6C\xEF\x45\xEE\x5D\x3C\x39\xED\xB0\x41\x62'
    iv = b'\xB3\x73\xBC\xD6\xBF\xF0\x41\x73\x17\x02\x15\x51\xB1\x09\x18\x43'
    encrypted = b'\x50\x1D\x75\xFA\x03\x2D\x77\x9E\x5D\x15\x42\x31\x53\x2B\x0B\x84'

    data = encrypted

    cipher = AES.new(key, AES.MODE_CFB, IV=iv)
    decrypted = cipher.decrypt(data)

    for i in decrypted:
        print("{:02X} ".format(i), end='')
    # should have decrypted to 74 65 73 74 20 70 61 73 73 65 64

#5 mORMot 1 » SynCrypto CFB/python » 2018-04-11 13:54:53

Denver
Replies: 8

#
# Im trying to interop Syncrypto with python, i have checked the iv/key/mode and they all match in Embarcadero® Delphi 10.1 Berlin Version 24.0.22858.6822  / python 3.6
# for now im ignoring the pkcs7 padding, python result is the same as using http://aes.online-domain-tools.com/
# i have tried with syncrypto using its native asm code and its pascal code, both produce same results, which is different from python code below
#
# on python code, only the first byte is decrypted correctly, if anyone else has any idea of what could be happening before i dig deeper into AES code, please let me know. thank you!
#
#
# delphi code
# inp := TAESCFB.SimpleEncrypt('test passed', 'testing', true, true, true);
# FileFromString(inp,'out.txt');
# inp := StringFromFile('out.txt');
# out := TAESCFB.SimpleEncrypt(inp, 'testing',false, true);


from Crypto.Cipher import AES
from Crypto.Hash import SHA256

def makekey(key):
    kl = chr(len(key))
    for i in range(0, 256-len(key)):
        key += kl
    return SHA256.new(key.encode("utf-8")).digest()

if __name__ == "__main__":

    key = makekey("testing")
    encrypted = b'\xB3\x73\xBC\xD6\xBF\xF0\x41\x73\x17\x02\x15\x51\xB1\x09\x18\x43\x50\x1D\x75\xFA\x03\x2D\x77\x9E\x5D\x15\x42\x31\x53\x2B\x0B\x84'

    iv = encrypted[0:16]
    data = encrypted[16:]

    cipher = AES.new(key, AES.MODE_CFB, IV=iv)
    decrypted = cipher.decrypt(data)

    for i in decrypted:
        print("{:02X} ".format(i), end='')
    # should have decrypted to 74 65 73 74 20 70 61 73 73 65 64

Board footer

Powered by FluxBB