Base64 encoding for user id/password REST API authentication

I need to authenticate using userid/password to get a token. However, the userid and password need to be Base64 encoded and sent as part of the header. How do I accomplish this using Custom Auth?