I am in the process of transferring functionality from an Objective-C iPhone application to a JavaScript iPhone application (using Appcelerator Titanium). In my Objective-C code, I have an NSData object that represents a specific token:
//NSData object shown when printed to the console:
<0cd9f571 b0e66e6d ca410d12 f67a404a 7e64b9b5 d2483fd9 63a9267b 1c7609e2>
This token is not just a string, it's actually an NSData object which serves as an object-oriented wrapper for a byte buffer. When I encode this object using base64, I obtain the following result:
//base64 encoded representation of the NSData object
DNn1cbDmbm3KQQ0S9npASn5kubXSSD/ZY6kmexx2CeI=
Now, in my JavaScript implementation, I have a string version of the same token which appears like this:
//string equivalent of the token in my JavaScript implementation
0cd9f571b0e66e6dca410d12f67a404a7e64b9b5d2483fd963a9267b1c7609e2
When I encode this string object using base64 in JavaScript, the output is as follows:
//base64 encoded token (as a string) in JavaScript
MGNkOWY1NzFiMGU2NmU2ZGNhNDEwZDEyZjY3YTQwNGE3ZTY0YjliNWQyNDgzZmQ5NjNhOTI2N2IxYzc2MDllMg==
The challenge arises because the web service I need to send this token to does not accept the base64 encoded string, but rather requires the base64 encoded data! How can I achieve this conversion in JavaScript?