in Education by
I'm porting functionality from an Objective-C iPhone app to a Javascript iPhone app (Appcelerator Titanium). In Objective-C I have an NSData object that represents this token: //NSData object printed to the console: <0cd9f571 b0e66e6d ca410d12 f67a404a 7e64b9b5 d2483fd9 63a9267b 1c7609e2> It's not a string, it's an NSData object -- an object-oriented wrapper for a byte buffer. When I base64 encode the object, I get this result: //base64 encoded NSData object DNn1cbDmbm3KQQ0S9npASn5kubXSSD/ZY6kmexx2CeI= In my javascript implementation, I have a string representation of the same token. It looks like this: //string version of the token in my javascript implementation 0cd9f571b0e66e6dca410d12f67a404a7e64b9b5d2483fd963a9267b1c7609e2 When I base64 encode the string object in javascript, I get this result: //base64 encoded token (string) in javascript MGNkOWY1NzFiMGU2NmU2ZGNhNDEwZDEyZjY3YTQwNGE3ZTY0YjliNWQyNDgzZmQ5NjNhOTI2N2IxYzc2MDllMg== The problem is, the web service I'm posting to doesn't want the base64 encoded string, it wants the base64 encoded data! How can I do this in javascript? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Convert the hexadecimal string before base64 encoding it should fix the issue. To do this in JS: if (! Array.prototype.map) { Array.prototype.map = function(f) { var result = []; for (var i=0; i < this.length; ++i) { result[i] = f(this[i], i); } return result; } } String.prototype.b16decode = function() { return this.match(/../g).map( function (x) { return String.fromCharCode(parseInt(x, 16)); } ).join(''); } For example, running btoa('0cd9f571b0e66e6dca410d12f67a404a7e64b9b5d2483fd963a9267b1c7609e2'.b16decode()) (where btoa is a base64 encoding function some browsers supply) results in "DNn1cbDmbm3KQQ0S9npASn5kubXSSD/ZY6kmexx2CeI="

Related questions

0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am trying to pass a dataString to to an ajax call using JQuery. In the call, I construct the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have a Date object. How do I render the title portion of the following snippet? A couple days ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    MapReduce jobs submitted from either Oozie, Pig or Hive can be used to encode, improve and sample the data sets ... of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Currently I am working on this code: customer_telno = customer.find('div', 'customer_phone_number') customer_telno = ... this problem? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128) ... anything which works consistently. Can anyone solve this problem?...
asked Nov 20, 2020 in Education by Editorial Staff
0 votes
    Which class implements an encoder for encoding byte data using the Base64 encoding scheme in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    Which class implements a decoder for decoding byte data using the Base64 encoding scheme in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    title basically. The question says create a function that takes in a string and returns true when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    title basically. The question says create a function that takes in a string and returns true when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    There are loads of questions about the current date in JavaScript in general, but in my scenario, I have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I'm trying to make it so when a user scrolls down a page, click a link, do whatever it is they ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I am trying to return an javascript value with Awesome lib in Vb.net / C#. Now I know how to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How will you create a Base64 encoder that encodes using the URL and Filename safe type base64 encoding scheme in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you create a Base64 decoder that decodes using the URL and Filename safe type base64 encoding scheme in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
...