How to encrypt the data

Posted by Mahesh_Chs under ASP.NET on 10/31/2012 | Points: 10 | Views : 840 | Status : [Member] | Replies : 2
i have a web page if i run that page and if i check the viewpage source then it is showing complete code, i want to encrypt the code.
how to encrypt the code..

Thank you


Posted by: Vasanthmvp on: 10/31/2012 [Member] Starter | Points: 25

Hi Mahesh,
We use html,asp server tags, etc in designing our web page, we include different functionality. A Web Browser converts that code to its own understandable DOM language (html, javascript, jquery, css, etc i.e from server level tags to web tags) which we see when we click on "View Page Source". That means we are actually showing the user only UI part of the page, but not the actual logic code.
I think we can restrict user from viewing this.. But, we have some tags with EnableViewStateProperty, Hidden, etc where we can reduce the data of a control that a page holds. It shows encrypted data here.
Some ways to do is: Disable right click of mouse by including a jquery code with OnMouseDown event or setting OnContentMenu to false.
We also have some software's like firebug to view the page source.
To know more on this, check this link:

Awesome Coding !! :)

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijay.K on: 11/1/2012 [Member] Starter | Points: 25

public static string EncryptString(string Message, string Passphrase)
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

// Step 1. We hash the passphrase using MD5
// We use the MD5 hash generator as the result is a 128 bit byte array
// which is a valid length for the TripleDES encoder we use below

MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));

// Step 2. Create a new TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

// Step 3. Setup the encoder
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;

// Step 4. Convert the input string to a byte[]
byte[] DataToEncrypt = UTF8.GetBytes(Message);

// Step 5. Attempt to encrypt the string
ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
// Clear the TripleDes and Hashprovider services of any sensitive information

// Step 6. Return the encrypted string as a base64 encoded string
return Convert.ToBase64String(Results);


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response