AESCrypt decryption between iOS and PHP

后端 未结 4 1595
失恋的感觉
失恋的感觉 2020-12-03 00:09

I am having a heck of a time figuring out how to decrypt a string encrypted with the NSData+AESCrypt.m (Explained here)

I have been looking at a handful of other thr

4条回答
  •  我在风中等你
    2020-12-03 00:43

    First off, the Objective-C code you're using is pretty terrible:

    • The keyspace is severely limited (presumably UTF-8 bytes terminated by a null byte, extended with null bytes to 32 bytes). The easiest way to generate a random key is to stick to ASCII, which limits you to about 223.6 bits for the default key size of 256 bits.
    • Encryption is done in ECB mode.
    • Data appears to be irreversibly padded with 0x0B.

    Avoid it at all costs. It is not secure.

    It can be "decrypted" in Python with something like this:

    >>> import Crypto.Cipher.AES
    >>> import base64
    >>> Crypto.Cipher.AES.new('a16byteslongkey!'+'\0'*16).decrypt(base64.b64decode('7opqbb7sEVNoXplyQv/X8g=='))
    'Hello\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b'
    

提交回复
热议问题