different result when encoding values from web.config

Viewed 183

I am trying to form a basic authentication header by getting a username and password from my web.config When I get these values from web.config, the base64 string is different than the ones I get from hard coding the values straight into the code.

This is my web.config:

 <?xml version="1.0" encoding="utf-8"?>
    <appSettings>
    <add key="Username" value="lowercaseusername"/>
    <add key="Password" value="mixedcasePassword​"/>
    </appSettings>

And my code:

var username = ConfigurationManager.AppSettings["Username"];
var password = ConfigurationManager.AppSettings["Password"];
string encodedValues = `Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));`

I get an extra "4oCL" at the end of the encoded string when I get them from web.config as opposed to hardcoded directly as values in the code

1 Answers
Related