We can use cryptography to secure our data from users over the network. We can implement cryptography in C# by using System.Security.Cryptography namespace. In this namespace we can use several classes to implement functionality of cryptography in c# such as SHA1 and MD5. In this blog we see how to use Cryptography in C#.
When we implement concept of Cryptography then we can use cipher value to encrypt data. Only those user can decrypt encrypted data who knows cipher value otherwise it is hard to decrypt it.

Following code demonstrate use of SHA1 algorithm

public static void encryptSha1() 
            string strText = "";
            Console.Write("Enter Name of Text--->   ");
            strText = Console.ReadLine();
            SHA1CryptoServiceProvider encrypt = new SHA1CryptoServiceProvider();
            byte[] encryptText = encrypt.ComputeHash(Encoding.Default.GetBytes(strText));
            foreach (byte tempData in encryptText)

Output of the following code snippet is as follows

Enter Name of Text--->   MindStick
Encrypted Value Is....`

Enter Name of Text--->   John Corner
Encrypted Value Is....

  Modified On Sep-18-2014 01:23:54 PM

Leave Comment