title: Whatsapp database decryption on Android
body: <p>I'd like to write an Android Application which automatically decrypts my Whatsapp Database, so I followed <a href="http://www.digitalinternals.com/security/decrypt-whatsapp-crypt7-database-messages/307/" rel="nofollow" title="this">this</a> tutorial and translated it into Java. But then I noticed that there is no openssl binary on Android so I asked google how to decrypt aes manually but I could not find something useful.</p>
  
  <p>So basically I got this shell command </p>
  
  <pre><code>openssl enc -aes-256-cbc -d -nosalt -nopad  -bufsize 16384 -in msgstore.db.crypt7.nohdr -K $k -iv $iv &gt; msgstore.db
  </code></pre>
  
  <p>with $k being a 64 digit hex-string. But when I tried to use it as the key for the aes decryption I get an InvalidKeyException with the message "Unsupported key size: 64 bytes".
  When I execute this command at my computer I works perfectly.</p>
  
  <p>I am currently using this java code to decrypt the database and it fails at cipher.init:</p>
  
  <pre><code>public void decryptDatabase(String k, String iv)
  
  throws InvalidKeyException, InvalidAlgorithmParameterException,
          NoSuchAlgorithmException, NoSuchPaddingException, IOException {
  
      File extStore = Environment.getExternalStorageDirectory();
      FileInputStream fis = new FileInputStream(extStore
              + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr");
      FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db");
  
      SecretKeySpec sks = new SecretKeySpec(k.getBytes(), "AES");
      Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
      cipher.init(Cipher.DECRYPT_MODE, sks,
              new IvParameterSpec(iv.getBytes()));
      CipherInputStream cis = new CipherInputStream(fis, cipher);
      int b;
      byte[] d = new byte[8];
      while ((b = cis.read(d)) != -1) {
          fos.write(d, 0, b);
      }
      fos.flush();
      fos.close();
      cis.close();
  }
  </code></pre>
  
  <p>Please help me if you can :)</p>
  
  <p>Thanks in advance, Citron</p>