Super secret. How to decode Base64 Basic Authentication!

OK, really not that secret.  Basic Authentication headers are pretty simple.  

When the server returns 401 and the header: WWW-Authenticate: Basic.  The server wants you to send the username and password in this format:  jeff:mypassword and then encode this as a Base64String.  You can encode this with this code: string secret = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(“jeff:mypassword”));.  To decode a username and password from a header that you send (found in the Authorization: Basic” header) pass that string to this: string decodedSecret = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(secret));

Comments (2)

  1. Alan McF says:


  2. Jeff Sanders says:

    PS, if you are not doing this programmatically you can use the Fiddler TextWizard to convert strings back and  forth.