Laguna
Laguna

Reputation: 3876

How to "iso-8859-1" encoding a string in jQuery?

I'm looking for a jQuery(or jQuery plugin) equivalent of this C# code block. What it does is to encode a string to base64 string in iso-8859-1 character set.

string authInfo = "encrypted secret";
Encoding encoding = Encoding.GetEncoding("iso-8859-1");
byte[] authBytes = encoding.GetBytes(authInfo);
string encryptedMsg = Convert.ToBase64String(authBytes);

Is there a plugin out there that can do this?

Upvotes: 1

Views: 1538

Answers (2)

Laguna
Laguna

Reputation: 3876

Found a jQuery plugin that's close enough to what I need: Base64 encode and decode It doesn't have an option to specify character set but I can live with it for now. So the jQuery code becomes:

authInfo = $.base64.encode(authInfo);

Upvotes: 1

Matthew
Matthew

Reputation: 25773

I believe you must specify the character encoding of the page (or where ever authInfo is defined) to ISO-8859-1. You may also specify the character encoding of the tag for referenced javascript files if authInfo is defined in one of those.

As for base64 encoding, here's a page that has a code snippet that does just that: http://www.webtoolkit.info/javascript-base64.html

Upvotes: 0

Related Questions