Open Whisper Systems, a non-profit, publishes open-source tools that do exactly what you need. WhatsApp and Open Whisper's own products use them.
More info:
https://en.wikipedia.org/wiki/Open_Whisper_Systems
https://www.whatsapp.com/security/WhatsApp-Security-Whitepap...