---
title: "Implementing Cryptography in C#.NET by using SHA1 Algorithm."  
description: "We can use cryptography to secure our data from users over the network. We can implement cryptography in C# by using System.Security.Cryptography name"  
author: "Anonymous User"  
published: 2011-02-15  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/119/implementing-cryptography-in-c-sharp-dot-net-by-using-sha1-algorithm  
category: "security in .net"  
tags: ["security in .net"]  
reading_time: 1 minute  

---

# Implementing Cryptography in C#.NET by using SHA1 Algorithm.

We can use cryptography to [secure](https://www.mindstick.com/articles/44535/smart-ways-to-secure-self-storage-facilities) [our data](https://yourviews.mindstick.com/view/70567/data-protection-bill-understanding-our-data) from users over the network. We can implement cryptography in C# by using System.Security.Cryptography [namespace](https://www.mindstick.com/articles/12552/namespace). In this namespace we can use several classes to implement [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) 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](https://www.mindstick.com/forum/158545/explain-the-concept-of-cryptography-and-its-role-in-securing-data-during-transmission-and-storage) then we can use cipher value to [encrypt data](https://www.mindstick.com/blog/687/encrypt-and-decrypt-data-with-c-sharp). 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](https://www.mindstick.com/blog/120/implementing-cryptography-by-using-md5-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](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes)\
Encrypted Value Is....`\
e13e312d85d994de9ee824bb647931e991405426

Enter Name of Text---> John Corner\
Encrypted Value Is....\
59aae33965199d7aecd93f419c046e625ad9

---

Original Source: https://www.mindstick.com/blog/119/implementing-cryptography-in-c-sharp-dot-net-by-using-sha1-algorithm

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
