It's quite easy. You just have to keep a copy of everybody's encryption keys so the government can use them. Of course, then it's no longer end to end encryption and any hacker that compromises the database of encryption keys can read everybody's messages.
By the way, WhatsApp is already end-to-end encrypted and so probably is Apple's message system. Furthermore, if no commercial end to end encryption system is available, it's pretty easy to knock one up. I reckon I could do it in a month.