Anders K
Anders K

Reputation: 503

Sha1 encryption of password when creating SOAP request in c#

Im trying to integrate using SOAP to a web service but I'm getting stucked in the authorization part, and more specifically when creating sha1 encrypted password. Documentation for this specific authorization can be found at https://www.beautyfort.com/api/docs/AuthHeader-t1

I have been searching the net trying to find different ways to create the password but none seems to generate the same password as the example in the documentation page.

string testDateString = "2015-07-08T11:31:53+01:00";
string testNonce = "186269";
string testSecret = "Ok4IWYLBHbKn8juM1gFPvQxadieZmS2";

SHA1CryptoServiceProvider sha1Hasher = new SHA1CryptoServiceProvider();
byte[] hashedDataBytes = sha1Hasher.ComputeHash(Encoding.UTF8.GetBytes(testNonce + testDateString + testSecret));
string Sha1Password = Convert.ToBase64String(hashedDataBytes);

The input variables is from documentation page. According to the documentation the password should get the value "ZDg3MTZiZTgwYTMwYWY4Nzc4OGFjMmZhYjA5YzM3MTdlYmQ1M2ZkMw==" but the code I am using is generating "2HFr6Aowr4d4isL6sJw3F+vVP9M=".

Anyone have a bright idea of what I am doing wrong?

Upvotes: 1

Views: 505

Answers (1)

Nebour
Nebour

Reputation: 95

I took a wild guess that maybe the output of "sha1()" in the documention psuedo-code was a hex-string (like sha1() in PHP, etc), and that seems to output the expected password.

Updated code:

string testDateString = "2015-07-08T11:31:53+01:00";
string testNonce = "186269";
string testSecret = "Ok4IWYLBHbKn8juM1gFPvQxadieZmS2";

SHA1CryptoServiceProvider sha1Hasher = new SHA1CryptoServiceProvider();
byte[] hashedDataBytes = sha1Hasher.ComputeHash(Encoding.UTF8.GetBytes(testNonce + testDateString + testSecret));

var hexString = BitConverter.ToString(hashedDataBytes).Replace("-", string.Empty).ToLower();
string Sha1Password = Convert.ToBase64String(Encoding.UTF8.GetBytes(hexString));

Upvotes: 1

Related Questions