title: Why does my initWithData return nil indicating an error after converting NSData to NSString returning from encrypting via CommonCrypto?
body: <p>Here is my code:</p>
  
  <pre><code>-(IBAction)encryptText:(id)sender
  {
  key = self.tvKey.text;
  
  CCCryptorStatus status = kCCSuccess;                                        
  algorithm = kCCAlgorithmAES128;                                                
  CCOptions opts = kCCOptionPKCS7Padding;
  
  NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
  
  NSString *plainString = [NSString stringWithFormat:@"%@", self.tvEntryText.text];
  NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];
  
  NSData *encryptedData = [plainData dataEncryptedUsingAlgorithm: algorithm     
                                                             key: keyData       
                                            initializationVector: nil             
                                                         options: opts           
                                                           error: &amp;status];    
  
  
  if ( status != kCCSuccess ) {
      NSError * err = [NSError errorWithCCCryptorStatus: status];
      self.lblKeyMsg.text = [NSString stringWithFormat:@"Encryption failed: %s", [[err localizedDescription] UTF8String]];
      self.lblKeyMsg.textColor = [UIColor redColor];
      return;
  }
  
  NSString *encryptedString = [[[NSString alloc] initWithData:encryptedData encoding:NSUTF8StringEncoding] autorelease];
  self.tvResultText.text = encryptedString;
  </code></pre>
  
  <p>}</p>
  
  <p>The second to last statement I am converting the encrypted NSData to an NSString for display purposes, but it comes back nil. Nil is a valid response indicating and error. I have stopped the execution right after that statement has run and here are the vaues:</p>
  
  <pre><code>(gdb) po keyData
  &lt;61616161 61616161 61617373 73737373 73737373 64646464 64646464 64646666&gt;
  (gdb) po key
  aaaaaaaaaassssssssssddddddddddff
  (gdb) po plainString
  this is a test.
  (gdb) po plainData
  &lt;74686973 20697320 61207465 73742e&gt;
  (gdb) po encryptedData
  &lt;f7074146 b295e340 0d947d53 9ea629cf&gt;
  (gdb) po encryptedString
  Can't print the description of a NIL object.
  (gdb) po status
  Can't print the description of a NIL object.
  (gdb) 
  </code></pre>
  
  <p>The status is nil indicating that there was NO error in the encryption. All values appear to be as expected, but the initWithData fails. Here is the operations iPhone view:</p>
  
  <p><img src="https://i.stack.imgur.com/SybFa.png" alt="The app screen when Encrypt button is pressed"></p>
  
  <p>Why is the initWithData failing here ? </p>