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
Shrikant Mishra
20-Aug-2020Sir, your article is undoubtedly of a high quality. With its help, we got more information about implementing cryptography.
Thanks...!!
Anonymous User
23-Feb-2019Thank You.
Sunil Singh
29-Jun-2017It was really helpful to read this post.