title: Sanitize Html with base64 image (and convert it to an image)
body: <p>I have a WebApp with a TinyMCE Html Editor that allows users to input some html from a web page. Images can be pasted and are encoded as base64.
  Before saving the user input to DB I use <a href="https://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project" rel="nofollow noreferrer">OWASP java-html-sanitizer</a> to discard potential dangerous code (javascript,...). </p>
  
  <p>Some characters in the base64 string of the image are escaped and when I try to get the image back (using apache commons Base64) I'm not able to get a valid image.</p>
  
  <p>Here my code for decoding the image:</p>
  
  <pre><code>byte[] b;
  String s = html;
  b = s.getBytes(Utility.UTF8);
  b = org.apache.commons.codec.binary.Base64.decodeBase64(b);
  </code></pre>
  
  <p>For the HtmlSanitizer I have done nothing special, just followed the <a href="https://github.com/OWASP/java-html-sanitizer/blob/master/src/main/java/org/owasp/html/examples/EbayPolicyExample.java" rel="nofollow noreferrer">Ebay Policy Example</a> allowing base64 images as suggested <a href="https://stackoverflow.com/questions/47345392/how-to-allow-embedded-images-when-sanitizing-html-with-owasp-java-html-sanitizer">here</a>.</p>