Hi
I am trying to pass an encoded string to a JavaScript
the following is the C# code which convert the string STRING_TO_ENCOD E to
base64
byte[] bytIn =
System.Text.Uni codeEncoding.Un icode.GetBytes( STRING_TO_ENCOD E);
string result=System.C onvert.ToBase64 String
the STRING_TO_ENCOD E contains both characters in Hebrew and English
I understand that JavaScript uses Unicode strings that is why I am using
UnicodeEncoding .Unicode.GetByt es
tha "result" variable is passed in the URL as a parameter
in the HTML i am using UTF8 char set
It DOES NOT WORK
Thanks 7 6795
"Julia" <co********@012 .net.il> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl I am trying to pass an encoded string to a JavaScript
the following is the C# code which convert the string STRING_TO_ENCOD E to base64
byte[] bytIn = System.Text.Uni codeEncoding.Un icode.GetBytes( STRING_TO_ENCOD E); string result=System.C onvert.ToBase64 String
the STRING_TO_ENCOD E contains both characters in Hebrew and English
I understand that JavaScript uses Unicode strings that is why I am using UnicodeEncoding .Unicode.GetByt es
tha "result" variable is passed in the URL as a parameter
It DOES NOT WORK
What exactly is "It" that "DOES NOT WORK"? What are you trying to do
with the result, and what problem do you have?
--
With best wishes,
Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
-I am trying to decode the encoded text to get the orginial text.
-the problem is that instead of hebrew characters i see other charactes(not
just '?')
after decoding.
-decoding is made using JavaScript.
-I don't have any error or exception.
-English characters are correctly displayed.
Thanks.
"Igor Tandetnik" <it********@mvp s.org> wrote in message
news:u0******** ******@TK2MSFTN GP11.phx.gbl... "Julia" <co********@012 .net.il> wrote in message news:OL******** ******@TK2MSFTN GP14.phx.gbl I am trying to pass an encoded string to a JavaScript
the following is the C# code which convert the string STRING_TO_ENCOD E to base64
byte[] bytIn = System.Text.Uni codeEncoding.Un icode.GetBytes( STRING_TO_ENCOD E); string result=System.C onvert.ToBase64 String
the STRING_TO_ENCOD E contains both characters in Hebrew and English
I understand that JavaScript uses Unicode strings that is why I am using UnicodeEncoding .Unicode.GetByt es
tha "result" variable is passed in the URL as a parameter
It DOES NOT WORK
What exactly is "It" that "DOES NOT WORK"? What are you trying to do with the result, and what problem do you have? -- With best wishes, Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
"Julia" <co********@012 .net.il> wrote in message
news:ej******** *****@tk2msftng p13.phx.gbl -I am trying to decode the encoded text to get the orginial text. -the problem is that instead of hebrew characters i see other charactes(not just '?') after decoding. -decoding is made using JavaScript.
How is decoding made using JavaScript? Show some code.
--
With best wishes,
Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Thanks
code for decoding
var base64 = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/' ]; // 56 to 63
function reverseBase64 () {
var r = new Object();
for (var i = 0; i < 64; i++) {
r[base64[i]] = i;
} return r;
}
var reversedBase64 = reverseBase64() ;
function decode (encStr) {
var charCodes = new Array();
var decStr = "";
for (var i = 0; i < encStr.length; i++)
charCodes[i] = reversedBase64[encStr.charAt(i )];
for (var i = 0; i < encStr.length; i += 4) {
var bits24 = ( charCodes [i] & 0xFF ) << 18;
bits24 |= ( charCodes [i + 1] & 0xFF ) << 12;
bits24 |= ( charCodes [i + 2] & 0xFF ) << 6;
bits24 |= ( charCodes [i + 3] & 0xFF ) << 0;
decStr += String.fromChar Code((bits24 & 0xFF0000) >> 16);
if (charCodes[i + 2]) // check for padding character =
decStr += String.fromChar Code((bits24 & 0xFF00) >> 8);
if (charCodes[i + 3]) // check for padding character =
decStr += String.fromChar Code((bits24 & 0xFF) >> 0);
} return decStr;
}
"Igor Tandetnik" <it********@mvp s.org> wrote in message
news:um******** ******@TK2MSFTN GP09.phx.gbl... "Julia" <co********@012 .net.il> wrote in message news:ej******** *****@tk2msftng p13.phx.gbl -I am trying to decode the encoded text to get the orginial text. -the problem is that instead of hebrew characters i see other charactes(not just '?') after decoding. -decoding is made using JavaScript.
How is decoding made using JavaScript? Show some code. -- With best wishes, Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
Julia <co********@012 .net.il> wrote: Thanks
code for decoding
var base64 = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55 '4', '5', '6', '7', '8', '9', '+', '/' ]; // 56 to 63 function reverseBase64 () { var r = new Object(); for (var i = 0; i < 64; i++) { r[base64[i]] = i; } return r; } var reversedBase64 = reverseBase64() ;
function decode (encStr) { var charCodes = new Array(); var decStr = ""; for (var i = 0; i < encStr.length; i++) charCodes[i] = reversedBase64[encStr.charAt(i )]; for (var i = 0; i < encStr.length; i += 4) { var bits24 = ( charCodes [i] & 0xFF ) << 18; bits24 |= ( charCodes [i + 1] & 0xFF ) << 12; bits24 |= ( charCodes [i + 2] & 0xFF ) << 6; bits24 |= ( charCodes [i + 3] & 0xFF ) << 0; decStr += String.fromChar Code((bits24 & 0xFF0000) >> 16); if (charCodes[i + 2]) // check for padding character = decStr += String.fromChar Code((bits24 & 0xFF00) >> 8); if (charCodes[i + 3]) // check for padding character = decStr += String.fromChar Code((bits24 & 0xFF) >> 0); } return decStr; }
That decoding is the problem. You're decoding it as if each byte is a
character, rather than each *pair* of bytes.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Julia" <co********@012 .net.il> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl for (var i = 0; i < encStr.length; i += 4) { var bits24 = ( charCodes [i] & 0xFF ) << 18; bits24 |= ( charCodes [i + 1] & 0xFF ) << 12; bits24 |= ( charCodes [i + 2] & 0xFF ) << 6; bits24 |= ( charCodes [i + 3] & 0xFF ) << 0; decStr += String.fromChar Code((bits24 & 0xFF0000) >> 16); if (charCodes[i + 2]) // check for padding character = decStr += String.fromChar Code((bits24 & 0xFF00) >> 8); if (charCodes[i + 3]) // check for padding character = decStr += String.fromChar Code((bits24 & 0xFF) >> 0); } return decStr; }
How do you expect to get any Unicode characters, if you never ever pass
a value outside [0-255] range to fromCharCode? You treat each byte as
representing a single character. But when you encoded, every character
was encoded as two bytes.
--
With best wishes,
Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Thanks Jon and Igor
I will try to fix it.
thanks for your help.
"Igor Tandetnik" <it********@mvp s.org> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl... "Julia" <co********@012 .net.il> wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl for (var i = 0; i < encStr.length; i += 4) { var bits24 = ( charCodes [i] & 0xFF ) << 18; bits24 |= ( charCodes [i + 1] & 0xFF ) << 12; bits24 |= ( charCodes [i + 2] & 0xFF ) << 6; bits24 |= ( charCodes [i + 3] & 0xFF ) << 0; decStr += String.fromChar Code((bits24 & 0xFF0000) >> 16); if (charCodes[i + 2]) // check for padding character = decStr += String.fromChar Code((bits24 & 0xFF00) >> 8); if (charCodes[i + 3]) // check for padding character = decStr += String.fromChar Code((bits24 & 0xFF) >> 0); } return decStr; }
How do you expect to get any Unicode characters, if you never ever pass a value outside [0-255] range to fromCharCode? You treat each byte as representing a single character. But when you encoded, every character was encoded as two bytes. -- With best wishes, Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael |
last post by:
I am trying to integrate my ASP page with an external application that
sends me a QueryString that is URLEncoded and each Name and Value in
the QueryString is Base64 Encoded as well.
---------------------------------------------------------------
Sample QueryString:
...
|
by: BW |
last post by:
Sorted my problem.
Issue - retrieve Base64 encoded Zlib compressed XML stream.
The compressed XML stream was compressed using Zlib on a Java
platform.
Resolution. (VB.NET)
1) Retrieve XML stream using webresponse class
|
by: John |
last post by:
Hi all,
I've been going through google and yahoo looking for a certain base64
decoder in C without success. What I'm after is something that you can
pass a base64 encoded string into and get back a decoded String.
Any help is very much appreciated.
Thanks
Philip.
|
by: Chris Fink |
last post by:
I have an xml document that contains some elements encoded as Base64. How do
I dynamically scan the XML Document and pull out the sections that are
Base64...
My overall goal is to display the XML document in a browser will all the
Base64 sections converted to Ascii (UTF-8).
|
by: kevin |
last post by:
DISCLAIMER: I know what the words mean (i.e. by definition), but I in know
way pretend to understand the specifics of either, therefore I may need a
basic primer before I can accomplish this task, but the instructions I
received do not seem correct.
I need to covert a hex string to base64 and was told to
1. convert from the HEX string to a byte array
2. convert the byte array to Base64 encoding
3. the two encodings would produce the...
| |
by: Phil C. |
last post by:
(Cross post from framework.aspnet.security)
Hi. I testing some asp.net code that generates a 256 bit Aes Symmetric Key
and a 256 bit entropy value.
I encrypt the Aes key(without storing it as Base64) with the host's dpapi
using the entropy value(without storing it as Base64),
and then store the encrypted Aes key value and the entropy value in some
SHARED VARIABLES AS BYTE ARRAYS(not Base64).
I then decrypt the stored encrypted Aes...
|
by: Tamir Weiss |
last post by:
I'm trying to send a byte array (JPG image) from javascript to a
servlet for processing.
I'm using Base64 to encode the byte array in javascript, and then a
base64 decoder in the servlet to decode it.
The thing is, that even though the String has the same length on both
sides, the decoded byte array is shorter then the original one.
I've tried a couple of different implementation on both sides, with
the same results.
|
by: aruna.eies.eng |
last post by:
i am currently trying to convert data into binary data.for that i need
to know how to achieve it in c language and what are the libraries
that we can use. so if any one can send me a sample code or send me
the library file which helps that is really grateful.
aruna.
|
by: Sam |
last post by:
Hi,
I am using some functions return a base64 encoded string.
The functions write it into an unsigned char buffer. I am a little
confused as to why a base64 encoded string would be using
an unsigned char buffer instead of a signed char buffer?
Also if I want to write this to file. Casting the buffer to
"char *" & then using fprintf seems to work, but this doesn't
seem right to me.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |