ascii vs. unicode

I have some functions to Encrypt and Decrypt data that is stored in a SQL Server database.  Sometimes these functions have to be javascript and sometimes they have to be vbscript...sometimes they need to be used by server code and sometimes by client code.

Here's my dilema, javascript methods(fromCharCode & charCodeAt) produce values in unicode.  I can get vbscript to operate in in unicode mode by using AscW and CharW.  As long as the data stays local, everything is fine.  I can interchange the function calls, and there is no problem.  

But, when I save the 'Encrypted' data to the database it's not equal to it's origional value back in the asp page.  Now the function that 'Encrypted' this is vbScript with the AscW & ChrW. It's like it doesn't know how to save the characters.  If I use Asc & Chr, saving the values as ascii and not unicode, things works great...until I try to 'Decrypt' with a jScript function because it's works in/with unicode and I'm supplying ascii code.  

Enough with the rambling...I guess my question is: How can I get a jScript function to work with ascii and not unicode?

Steve
LVL 4
Steve SiricaSenior Web Application EngineerAsked:
Who is Participating?
 
CJ_SConnect With a Mentor Commented:
You can use JScript and VBScript together, just define the languages. Then make one function in either language to save and retrieve the data.

<script language="JScript" runat="server">
function myfunc()
{

}
</script>
<script language="VBScript" runat="server">
public sub myfunction()
   myfunc()
end sub
</script>

Another way is to change the database (I think it should be sufficient, but don't pin me on it). if the database is SQL Server you can change the data type. For example nvarchar is a unicode text field. To make sure that the SQL statement is sure of it's unicode value you can use N'yourvalue' (select N'myvalue'). Oracle will have some similar manner, not access.

CJ
0
 
Steve SiricaSenior Web Application EngineerAuthor Commented:
Just closing out some open questions, and you were the only one who answered, so you get the points by default.
0
All Courses

From novice to tech pro — start learning today.