Jeff Sanders Technical Blog

I am a Microsoft employee that has worked on all aspects of the Web Stack for a long time. I hope these blogs are useful to you! Use this information at your own risk.


<< Go Back

Super Secret How To Decode Base64 Basic Authentication

- 17 Mar 2011

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));

<< Go Back