c# - How to write javascript equivalent of Convert.ToBase64String() in javascript? -


this question has answer here:

i have byte array , can convert usin convert.tobase64string() method in c#. wrote equivalent of method in javascript below. result different.

in c#:

 byte[] data = ... convert.tobase64string(data) 

in js

    function getstringfrombytearray(array) {         var result = "";         (var = 0; < array.length; i++) {             (var j = 0; j < array[i].length; j++)                 result += string.fromcharcode(array[i][j]);         }         return result;     } 

how can succeed in js?

yes, result different, because javascript function doesn't base64 encoding @ all.

the base64 encoded data contains 6 bits of information per character, 8 bits of character code spread out on 2 characters in encoded data.

to encode data, have regroup bits in bytes 6 bit groups, can convert each group base64 character.

see: base64


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -