title: aes decryption \0 character ios
body: <p>i've a problem..when i decrypt the data that is returned from my php page,
  if the length of the string is less than 16, the char \0 is append to string. 
  Original string is: <strong>100000065912248</strong>
  I decrypt the encrypted string with this function:</p>
  
  <pre><code>#define FBENCRYPT_ALGORITHM     kCCAlgorithmAES128
  #define FBENCRYPT_BLOCK_SIZE    kCCBlockSizeAES128
  #define FBENCRYPT_KEY_SIZE      kCCKeySizeAES256
  
  + (NSData*)decryptData:(NSData*)data key:(NSData*)key iv:(NSData*)iv;
  {
      NSData* result = nil;
  
      // setup key
      unsigned char cKey[FBENCRYPT_KEY_SIZE];
      bzero(cKey, sizeof(cKey));
      [key getBytes:cKey length:FBENCRYPT_KEY_SIZE];
  
      // setup iv
      char cIv[FBENCRYPT_BLOCK_SIZE];
      bzero(cIv, FBENCRYPT_BLOCK_SIZE);
      if (iv) {
          [iv getBytes:cIv length:FBENCRYPT_BLOCK_SIZE];
      }
  
      // setup output buffer
      size_t bufferSize = [data length] + FBENCRYPT_BLOCK_SIZE;
      void *buffer = malloc(bufferSize);
  
      int length = [data length];
  
      // do decrypt
      size_t decryptedSize = 0;
      CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
                                            FBENCRYPT_ALGORITHM,
                                            0,
                                            cKey,
                                            FBENCRYPT_KEY_SIZE,
                                            cIv,
                                            [data bytes],
                                            [data length],
                                            buffer,
                                            bufferSize,
                                            &amp;decryptedSize);
  
      if (cryptStatus == kCCSuccess) {
          result = [NSData dataWithBytesNoCopy:buffer length:decryptedSize];
      } else {
          free(buffer);
          NSLog(@"[ERROR] failed to decrypt| CCCryptoStatus: %d", cryptStatus);
      }
  
      return result;
  }
  </code></pre>
  
  <p>I send a nil "iv" parameter to the function and after i use "cIv" in function, and it contain this:
  <img src="https://i.stack.imgur.com/Kr6Je.png" alt="cIv description"></p>
  
  <p>The result is exactly, but the length of string is 16 instead of 15 (string: 100000065912248). In fact, the last character is \0.</p>
  
  <p>Why? how can i solve?</p>
  
  <p>EDIT:</p>
  
  <p>PHP encrypt function:</p>
  
  <pre><code>function encrypt($plaintext) {
  
      $key = 'a16byteslongkey!a16byteslongkey!';
  
      $base64encoded_ciphertext = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC));
      $base64encoded_ciphertext = trim($base64encoded_ciphertext);
  
      return $base64encoded_ciphertext;
  }
  </code></pre>