title: Compute a checksum on the iPhone from NSData
body: <p>Using the iPhone SDK, I'm having the user select images from the image picker. If the user selects an image they've selected before, I'd like to make the user aware of it.</p>
  
  <p>My initial plan (just to make sure other things work for now) is to save the image to a file (need to do this anyway for other reasons), using a checksum of the NSData as the filename. Then, when they select the same image later on, the checksum will be the same and so I can see that a file with that name already exists - hurrah!</p>
  
  <p>However, I've scoured the internet and the Apple docs for how to compute a checksum from a NSData. I know I could implement my own implementation, but I'd prefer to avoid that, if possible. I'm also happy for other ideas of how to check that two UIImages are the same.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Two years ago I promised a code sample, and here it is. Really sorry for the delay! :)</p>
  
  <pre><code>+(NSString*)imageIdForData:(NSData*)data
  {
          char* result = (char*) [[data MD5Sum] bytes];
  
          NSString* hash =  [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
                                             result[0], result[1],
                                             result[2], result[3],
                                             result[4], result[5],
                                             result[6], result[7],
                                             result[8], result[9],
                                             result[10], result[11],
                                             result[12], result[13],
                                             result[14], result[15]];
  
          return hash;
  }
  </code></pre>