Home > DeveloperSection > Blogs > Implementing Cryptography in C#.NET by using SHA1 Algorithm.

Implementing Cryptography in C#.NET by using SHA1 Algorithm.


Security in .Net Security in .Net 
Ratings:
0 Comment(s)
 6855  View(s)
Rate this:

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)

            {

                Console.Write(tempData.ToString("x"));

            }

            Console.WriteLine();

}

Output of the following code snippet is as follows

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

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


Don't want to miss updates? Please click the below button!

Follow MindStick