title: Create checksum from base64 or raw data?
body: <p>In my project, I need to transfer image via API. Before transfer, I'm encoding raw image data with <code>base64</code> so I can use it in JSON request. What I want to do is add checksum of file to request so I can test on my API side if file was transfered successfully. </p>
  
  <p>My question is - should I calculate checksum before or after base64?</p>
  
  <pre><code>// Client
  $checksum = md5($rawImageData);
  $base64ImageData = base64_encode($rawImageData);
  
  // API
  $receivedBase64 = $_POST['base64ImageData'];
  $receivedChecksum = $_POST['checksum'];
  $imageData = base64_decode($receivedBase64);
  $actualChecksum = md5($imageData);
  
  if ($receivedChecksum != $actualChecksum) {
     // Image not transfered correctly.
  }
  </code></pre>
  
  <p>Or should I at first encode data with <code>base64</code>, then calculate md5 checksum and on API side, compare it with checksum of received base64? Or it doesn't matter and both solutions have same reliability? Thanks</p>