# Secure your data with Triple DES Encryption

Data security is very crucial thing now days, hackers are always ready to dig a leak hole in your data line and grab your valuable information. This article will let teach the technique to encrypt your data and make it safe. Using Triple DES Encryption technique you can be able to encrypt/decrypt your data. The encryption is done with the help of your key.

### Introduction

Now a days data security is a big aspect in any industry, all data and information we share on air with the help of wireless routers, LAN, WAN. There are many Intruder/hacker present in the rout and they are searching for a chance to hack the valuable information.
To overcome this issue encryption technique get in to world
After reading this resource you can be able to encrypt your data and hence strengthn the security

### What is encryption ?

Encryption is the activity of converting data or information into code and that code has some encoded form called cipherText. That can not be easily understood by unauthorized people. Encryption can be done with the help of cryptography.
it also helps us to protect data from being viewed, provides ways to detect whether data has been modified.

### What are the ways to encrypt our information ?

To overcome above issue different algorithms are developed to make data more secure and more encoded. Here is list of some encryption algorithms

1.AES
2.Blowfish
3.DES
4.Triple DES
5.Serpent
6.Twofish
7.Camellia
8.CAST-128
9.IDEA,RC2,RC5,SEED,Skipjack,TEA,XTEA etc

In this article we discuss about 'Triple DES' encryption technique and it's usage. we also discuss how to use it in program to encrypt Text. So basically you can be able to encrypt/decrypt your valuable information with it.

### How it works

TripleDES algorithm uses three successive iterations of the DES algorithm for encrypting data, To do the encryption TripleDES use a secure key which generate a different cipher text for each data. This algorithm supports key lengths from 128 bits to 192 bits in increments of 64 bits. Same key is used for encryption and decryption.
Here This code will convert our plain text in Byte array, then create/provide a key for encryption. And then apply encryptor on it. With the help of encrypted key we transform the plain text blocks and then return a cipher text as output

http://en.wikipedia.org/wiki/Data_Encryption_Standard

### Code view

we can implement encryption using Triple DES algorithm in .NET with the help of System.Cryptography namespace.
check for the following code snippet to encrypt data/file

`//I have a write a below function to encrypt a data using Triple DES algorithm//This function accept two parameters //1.String to which you want to encrypt//2.Key for encryption//Remember here, the key you are provide should ranging from 128 bits to 192 bits or you can take help of GenerateKey() method of 'TripleDESCryptoServiceProvider' class//Here i used key for encryption is "HelloWorld!00000" public static string Encrypt_text(string input, string key) { byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input); TripleDESCryptoServiceProvider objtripleDESProvider = new TripleDESCryptoServiceProvider(); //objtripleDESProvider.GenerateKey(); //we can provide a key or we can generate a key by using GenerateKey() method of TripleDES provider class tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); //MessageBox.Show(Convert.ToBase64String(objtripleDESProvider.Key,0,objtripleDESProvider.Key.Length)); objtripleDESProvider.Mode = CipherMode.ECB; objtripleDESProvider.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = objtripleDESProvider.CreateEncryptor(); byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); objtripleDESProvider.Clear(); return Convert.ToBase64String(resultArray, 0, resultArray.Length); }`

The encrypted text is look like a corrupted file and its a really fuzzy text
here we can decrypt data the same we encrypt it
go through following code snippet, which gives you more idea about it

` public static string Decrypt_text(string CipherText, string key) { byte[] inputArray = Convert.FromBase64String(CipherText); TripleDESCryptoServiceProvider objtripleDESProvider = new TripleDESCryptoServiceProvider(); objtripleDESProvider.Key = UTF8Encoding.UTF8.GetBytes(key); objtripleDESProvider.Mode = CipherMode.ECB; objtripleDESProvider.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = objtripleDESProvider.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); objtripleDESProvider.Clear(); return UTF8Encoding.UTF8.GetString(resultArray); }`

### Common usage of Triple DES :

Triple DES algorithm is commonly used in electronic payment industry where for transfer transaction Triple DES is used and These industries are continues to develop and promulgate standards based upon it (e.g. EMV). even, Microsoft Outlook 2007 and Microsoft System Center Configuration Manager 2012 use Triple DES to password protect user content and system data.

### Final touch

finally we have encrypt our data successfully and secure it in smooth way. This pattern can be used for encrypting Files too.
but this is the only start for encryption, in next version of this article we will see a different algorithm to encrypt, mean while you can enjoy this encryption to make your data secure.

Suggestions and feedbacks are most welcome.......!

Thanks