Skip to main content

Posts

Encrypting and Decrypting Query Strings in asp.net

Introduction
We often pass values between pages in the form of a query string as key-value pairs. Query string is the easiest way and most widely practiced mechanism of transferring small pieces of data between web pages. The end-user may change the value in the query string to play around with the application, and at the same time, it leads to compromising the security and data integrity of the system. So the solution is encrypting the query strings.

Following is the simple way of encryption and decryption mechanism in asp.net

First I created two methods for encryption and decryption

Encrypt the string


private string Encrypt(string stringToEncrypt)
         {
             byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
             byte[] rgbIV = { 0x21, 0x43, 0x56, 0x87, 0x10, 0xfd, 0xea, 0x1c };
             byte[] key = { };
             try
             {
                 key = System.Text.Encoding.UTF8.GetBytes("A0D1nX0Q");
                 DESCryptoSe…

Sending Email using your GMail Account in C#.NET

Use System.Net.Mail namespace, not the deprecated System.Web.Mail. Doing SSL with System.Web.Mail will get security problemsvar client = new SmtpClient
            {
//create a host
                Host = "smtp.gmail.com",
//gmail uses port number 587
                Port = 587,
//Enable Secure Communication
                EnableSsl = true,
//Set delivery method to Network
                DeliveryMethod = SmtpDeliveryMethod.Network,
//Give the Credentials
                Credentials = new NetworkCredential("yourusername@gmail.com", "yourPassword"),
//Set some timeout
                Timeout = 20000
            };
//Create a MailMessage Object
            using (var mailMessage = new MailMessage("yourusername@gmail.com", toEmailId)
            {
//add subject and EmailBody(content) to Mail Message object
                Subject = “Subject of the Email”,
            …