Encrypt the url parameter

How to encrypt the id parameter in the url when the view and edit events?

For example the original url
http://localhost:8050/workingpermit/edit/4

becomes
http://localhost:8050/workingpermit/edit/{encryption code}