Q:

How to Decrypt using Javascript

I have a  captcha text,which I am storing in hidden variable and retreiving the value in code behind(c#.net).
Now I need to Encrypt that captcha text and store in hidden variable and decrypt the same in c#.net
I need an algorithm that works both in javascript and c# .i.e encrypt in javascript and decrypt in c#.net.
eg : text : "dfg563hj"
Thanks for your help in advance.
Ramesh.

A:

I also do not think this is a good idea because they'd be able to see how to do the decryption..
Here's javascript for doing a DES decryption
http://www.teslacore.it/sssup1/des.js
you just need to call   
encryptedText = des(password, unHex(contents), 0);

Here's c# for doing DES encyption
public static string Encrypt(string originalString)
{
    if (String.IsNullOrEmpty(originalString))
    {
        throw new ArgumentNullException
               ("The string which needs to be encrypted can not be null.");
    } 
    DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
    MemoryStream memoryStream = new MemoryStream();
    CryptoStream cryptoStream = new CryptoStream(memoryStream, 
        cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
    StreamWriter writer = new StreamWriter(cryptoStream);
    writer.Write(originalString);
    writer.Flush();
    cryptoStream.FlushFinalBlock();
    writer.Flush();
    return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
}

