php99
php99

Reputation: 71

Why is base64 using CryptoJS different than a standard base64 encode?

To communicate with a server, I need to send the password SHA1 & base64 encoded the same way CryptoJS does this.

My problem is that I'm using VB.NET. The typical base64 encoding (UTF-8) result is different than the results of CryptoJS.

How can I base64 encode the SHA1 string in .NET the same way CryptoJS encodes it?

You can see both results here: https://jsfiddle.net/hn5qqLo7/

var helloworld = "Hello World";
var helloword_sha1 = CryptoJS.SHA1(helloworld);
document.write("SHA1: " + helloword_sha1);

var helloword_base64 = helloword_sha1.toString(CryptoJS.enc.Base64);
document.write("1) Base64: " + helloword_base64);
document.write("2) Base64: " + base64_encode(helloword_sha1.toString()));

where base64_encode converts a given string to a Base 64 encoded string.

I saw a similar question, but I don't understand it. Decode a Base64 String using CryptoJS

Upvotes: 1

Views: 1810

Answers (1)

Ewoud
Ewoud

Reputation: 751

In (1) of your fiddle the CryptoJS calculates the SHA1 value of the string, and then, converts the raw bytes to Base64. However (2) first calculates the SHA1 value of 'Hello World' and then puts it in hexadecimal form (consisting of only 0-9 and a-f), and then converts this hexadecimal form of SHA1 to base64. So that is why you end up with two different results.

Upvotes: 3

Related Questions