title: How to encrypt file from SD card using AES in Android?
body: <p>I want to encrypt image from the sd card and store it again in SD card again using AES. The main idea is the application browse an image, then encrypt it when I push a button, then store it in sd card. so my image would be secure. </p>
  
  <p>I already succeed do string encryption using AES from this tutorial <a href="http://www.androidsnippets.com/encryptdecrypt-strings" rel="noreferrer">http://www.androidsnippets.com/encryptdecrypt-strings</a>, but I don't have idea how to do this with an image, not string.</p>
  
  <p>This is how I do it with a string:</p>
  
  <pre><code>public static String encrypt(String seed, String cleartext) throws Exception  
  {
      byte[] rawKey = getRawKey(seed.getBytes());
      byte[] result = encrypt(rawKey, cleartext.getBytes()); 
      return toHex(result);
  }
  
  private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception 
  {
      SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
      Cipher cipher = Cipher.getInstance("AES");
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
      byte[] encrypted = cipher.doFinal(clear);
      return encrypted;
  }
  </code></pre>
  
  <p>Can anyone help me give example code how to encrypt <strong>an image</strong> with AES?</p>
  
  <p>maybe it must using I/O file stream but I don't have an idea how to implement with this code.</p>