Mattersphere Developers Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

C# Winform Application: Decoding 64bit Web Tokens On 32bit Client Machines Empty C# Winform Application: Decoding 64bit Web Tokens On 32bit Client Machines

Tue 4 Feb 2020 - 8:29
My company has an external pointing web server that allows our clients to complete questionnaires and submit the results to the Mattercentre database.
Each external user's form gets a unique GUID. For example [9C43207A-FD84-499A-82C3-247E7337335F]. For security purposes a token is generated with C# code
using the form GUID, on the 64 bit web-server.
In order for an internal user to see the form, in our winforms application, a web browser has been embedded and the following URL is entered into a web
browser.value... [https://company_domain_name.com/formonline.aspx?token=TOKEN_GENERATED_BY_64_BIT_WEBSERVER].
The code below generates the token...
//**************************************************************
// Example Code
//**************************************************************
System.Guid MY_GUID =
new System.Guid(“9C43207A-FD84-499A-82C3-247E7337335F”);
string txtID = MY_GUID.ToString();
System.Text.StringBuilder str =
new System.Text.StringBuilder();
str.Append(txtID);
//**************************************************************
// Other string values are appended to StringBuilder for
// security reasons
//**************************************************************
string hashResult = txtID.GetHashCode().ToString();
str.Append(hashResult);
string finalResult = EncodeTo64(str.ToString());
//**************************************************************
// Method
//**************************************************************
private string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes =
System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string returnValue =
System.Convert.ToBase64String(toEncodeAsBytes);
return returnValue;
}

Unfortunately the web token generated on the internal users 32bit client machine is completely different from the web server version and the web page fails to open. Actual Examples below...

[GUID] [9C43207A-FD84-499A-82C3-247E7337335F]

[64bit Token] [OWM0MzIwN2EtZmQ4NC00OTlhLTgyYzMtMjQ3ZTczMzczMzVmI1RydWUjLTMyMDYzMzU4MQ==]

[32bit Token] [OWM0MzIwN2EtZmQ4NC00OTlhLTgyYzMtMjQ3ZTczMzczMzVmI1RydWUjMTI2NzI2MzQ1Mg==]

Downgrading the web server from 64bit to 32bit is not an option.

Altering the code on the web server is also not an option, as it is a proprietary software system and I was very lucky that the developers gave me the code that they use to create the token.

Is it even possible to use the calculation to get the same 64bit result on a 32bit client?

avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

C# Winform Application: Decoding 64bit Web Tokens On 32bit Client Machines Empty Re: C# Winform Application: Decoding 64bit Web Tokens On 32bit Client Machines

Tue 4 Feb 2020 - 8:30
Unfortunately this looks like expected behaviour. Its the GetHashCode Method that is the problem according to the documentation below (In the Important bit)its not guaranteed to be stable across platforms for .Net Framework versions.
http://msdn.microsoft.com/en-gb/libra...
The only way I can think of you getting a solution to thisis to create a web service (On the assumption you can change the winform application) Create a simple Webservice with one methodwhich you would installon your 64bit webserver.
This servicewould have one method which would take the GUIDand then run the code below to create the Token by added the Hash to it and then returning that string or the whole URL to save further processing on the Winform Side. Since its created on the same system as the External Request it should return the same result.
If you cannot put a webservice on that external server maybe you could create your own ensuring the same Version of Windows and .NET Framework? You could then just call this service from the winform side to get the URL for the Embedded browser.
Not sure if that helps, but might work for you.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum