Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to decode basic authorization in .NET

I need to validate a basic authorization header that is being sent to my HttpListener in VB.NET. I'm grabbing the header like so (feel free to point out better ways to do this as well):

EncodedAuth = Context.Request.Headers.GetValues("Authorization")(1)

Now how do I decode them? I understand the theory but I can't seem to find the right code.

Thank you.

like image 443
Ryan Avatar asked May 08 '09 18:05

Ryan


1 Answers

This should do it...

basicData = System.Text.ASCIIEncoding.ASCII.GetString( System.Convert.FromBase64String( EncodedAuth ) )

This will give you a string in the format "username:password". Split the string on ":" and you'll get the credentials.

like image 84
David Avatar answered Sep 24 '22 14:09

David