asp.net - different result when encoding values from web.config -


i trying form basic authentication header getting username , password web.config when these values web.config, base64 string different ones hard coding values straight code.

this web.config:

 <?xml version="1.0" encoding="utf-8"?>     <appsettings>     <add key="username" value="lowercaseusername"/>     <add key="password" value="mixedcasepassword​"/>     </appsettings> 

and code:

var username = configurationmanager.appsettings["username"]; var password = configurationmanager.appsettings["password"]; string encodedvalues = `convert.tobase64string(system.text.encoding.utf8.getbytes(username + ":" + password));` 

i "4ocl" @ end of encoded string when them web.config opposed hardcoded directly values in code

your web.config have utf-8 encoding. if copy-pasted password , set web.config encoding iso-8859-1:

<?xml version="1.0" encoding="iso-8859-1"?> 

that's when getting value config:

mixedcasepasswordâ\u0080\u008b

this should correspond to

mixedcasepassword​

so there's invisible characters have been incorrectly encoded in web.config.

the web.config file xml file, values need encoded. if set in web.config (keeping encoding @ utf-8):

<add key="password" value="mixedcasepassword&#226;&#8364;&#8249;" /> 

you should have true if test:

configurationmanager.appsettings["password"] == "mixedcasepassword​" 

then base64 should match if password web.config or hard coded.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -