This is an exerpt from an Android App that I created to decrypt WhatsApp backup files according to the python script mentioned in this blog:
http://bas.bosschert.nl/steal-whatsapp-update/
I just translated it to Java in order to enable the decryption directly on the device without using Python.