2

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.

4
  • 2
    Its would be waist if javascript was able to encrypt/decrypt the value. Anyone would be able to view the javascript and see what key/algorithm you are using to do the "encryption". Commented Mar 9, 2011 at 7:30
  • encrypting & decrypting in JavaScript will expose the encryption codes to public. People can decrypt it using your codes. It is suggested to put all encryption codes in server side. Commented Mar 9, 2011 at 7:31
  • 1
    @The Scrum Meister, @Shivan: You can encrypt with a public key, and decrypt with a private key. This is the basis of PGP, for instance. So it does not necessarily expose anything private to be doing the public part on the client browser. You gain en route tamper detection, but @user note that you gain nothing in terms of intentionally-spoofed messages reaching your server. Commented Mar 9, 2011 at 7:33
  • Does the PO want the entered text to be encrypted, or want to have the captcha text itself on client side? Commented Mar 9, 2011 at 7:35

2 Answers 2

2

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

The link is broken.
0

Whether such an encryption exists or not, it would be a bad idea to have Captcha text in Client side and modified using JavaScript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.