title: AES_DECRYPT How do you check value is already decrypted in mysql
body: <p>I want to decrypt fields in my database using sql on mysql but before I decrypt I need to check if the fields can be decrypted.</p>
  
  <pre><code>update customer
  set name = aes_decrypt(from_base64(name), 'key')
  </code></pre>
  
  <p>If the provided key is wrong or data is invalid the name field will be set to null;</p>
  
  <p>I have tried adding a where clause like below to make sure the field name is not already decrypted but this doesn't work all the time as the aes_decrypt can return null or garbage if the key is incorrect or data is invalid.</p>
  
  <pre><code>update customer
  set name = aes_decrypt(from_base64(name), 'key')
  where aes_decrypt(from_base64(name), 'key') is not null.
  </code></pre>
  
  <p>So how can I check if the returned value is null or "garbage"? Or what other approach is there?</p>
  
  <p>From mysql doc: "it is possible for AES_DECRYPT() to return a non-NULL value (possibly garbage) if the input data or the key is invalid."</p>
  
  <p>garbage example I get: w���� ��Y�'v��Y�m��_</p>
  
  <p>Thanks</p>