Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Disclaimer: I have zero iPhone development experience.</p> <p>Short answer - what tc. said. Something is horribly wrong with the <code>AES256EncryptWithKey</code>:</p> <p>Being AES256 you would expect it to require a 32 byte key, not a 16 byte key. But OK, say it pads shorter keys with null bytes to make them 32 bytes. This might explain why your 16 byte key is being padded with 16 null characters.</p> <p>But, when it comes to the actual act of encryption, it's using AES 128, but with the 32 byte key. Say wha?</p> <p>Converting tc.'s Python to PHP:</p> <pre><code>$base64encoded_ciphertext = '7opqbb7sEVNoXplyQv/X8g=='; $key = 'a16byteslongkey!'; $padded_key = $key . str_repeat(chr(0x00), 16); // Argh! $result = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $padded_key, base64_decode($base64encoded_ciphertext), 'ecb'); // Yetch - $result ends up being padded with 0x0b's (vertical tab). var_dump(rtrim($result, chr(0x0b))); </code></pre> <p>Result:</p> <blockquote> <p>string(5) "Hello"</p> </blockquote> <p>~~</p> <p>Edit: <a href="https://stackoverflow.com/questions/4540725/iphone-aes-256-encryption-without-padding/4541114#4541114">This post</a> from Henno has some relevant details.</p> <p>~~</p> <p>Did some additional research. The null padding on your key is likely because AES256 requires a 32 byte key. The 0x0B padding on the plaintext is thanks to <a href="http://tools.ietf.org/html/rfc5652#section-6.3" rel="nofollow noreferrer">PKCS7</a>. PKCS7 is a padding scheme where the byte used for padding is equal in value to the number of bytes added. In this example, 11 bytes were added to the end of 'Hello' turning your 5 byte input into a 16 byte block for AES. 11 = 0x0B.</p> <p>Thus, the code above will not work when the plaintext is not length = 5. Try the following instead:</p> <pre><code>$pad_char = ord(substr($result, -1)); $result_without_padding = substr($result, 0, strlen($result) - $pad_char); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload