The easiest way to decode basic authorization in .NET.

I need to check the basic authorization header that is sent to my HttpListener in VB.NET. I grab the title like this (feel free to point it out better):

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

Now how do I decode them? I understand the theory , but I cannot find the correct code.

Thanks.

+4
source share
1 answer

That should do it ...

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

This will give you a string in the format "username: password". Divide the line by ":" and you will get the credentials.

+9
source

All Articles