5

I'm running some tests comparing the sha1 algorithm implemented in javascript - got from http://pajhome.org.uk/crypt/ - with its implementation in C#.

Using C# to get the hash for {'method':'people.get'} I'm using this statement:

Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes("{'method':'people.get'}")));

which gives me Qy95a0ShZqhbNdt6IF8qNf72jX0=

In javascript I get almost the same: Qy95a0ShZqhbNdt6IF8qNf72jX0 using the statement:

b64_sha1("{'method':'people.get'}");

In the javascript case, the hash doesn't end with a equal (=) sign.

Can this difference cause me troubles in authenticating against a server?

In my case, as many of you may know, the sentence I'm reckoning the hash goes inside the http body and the server will check it.

Thanks

2 Answers 2

5

Would depend on the receiver but try decoding your result from the javascript with C# and you'll get an exception. The = sign is there to pad the result to the correct length.

http://en.wikipedia.org/wiki/Base64

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, based on that information I saw now that the = sign, as you pointed out, is used for padding the message. Thanks
@Andres: You can update line 15 of the sha1.js file from pajhome.org.uk to use = as the padding character.
Yes, while I was writing the my own answer you were writing this remark. Thanks :)
You could strip all = signs at the end befiore comparison (or pad with = signs to the correct length)
4

The sha1.js from the lib I mentioned in my question, has a global variable called b64pad, used for the purpose of padding. By default its value is "". Changing to "=" gives the exact hash reckoned by C# API

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.