Saturday, December 6, 2008

Javascript and C# encryption

If you are unable to use SSL and you want to use encryption, one option is to use javascript to encrypt and send your data. Then on the server side you can decrypt the data, process it, and send back an encrypted response to be decrypted by javascript.

I have created a page which does this. I used AES (also known as Rijndael) for the private key encryption algorithm. The .NET framework has a built-in class library implementation of this called System.Security.Cryptography.RijndaelManaged and there are some javascript implementations out there on the web. I copied one of them and made some modifications to it, such as adding Base64 encoding.

The private key is hard coded in the server side code and must be entered into a textbox on the page by the user.

Download the code

3 comments:

Andrés said...
This comment has been removed by the author.
Andrés said...

Javascript->C# AES Encrypt/Decrypt

This code is awesome, is working properly and helped me a lot on my project, thank you very much Mark, you rock!!

I'm planning to create a simplified version of it using jquery ajax, look for it on my blog soon http://www.andresmeza.com

Unknown said...

Thanks very much, helped me a lot.