SIGN UP MEMBER LOGIN:    
ARTICLE

How we Decrypt the Text File using DES Method in ASP.Net: Part 2

Posted by Brijesh Jalan Articles | Cryptography C# August 16, 2010
In this article we will learn how to decrypt a Encrypted text file.
Reader Level:

Click here for Part 1 of the article.

How we Decrypt the text File using DES method.

1. Open visual studio and create a project

2. Add the following assembly on the page

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.IO;

3. Now write the code in the Page

public class Tester
{
    public static void Main()
    {
        try
        {
            DESCryptoServiceProvider myDESProvider = new DESCryptoServiceProvider();
              myDESProvider.Key = ASCIIEncoding.ASCII.GetBytes("12345678");
             myDESProvider.IV = ASCIIEncoding.ASCII.GetBytes("12345678");
             FileStream DecryptedFile = new FileStream("testDes.txt", FileMode.Open, FileAccess.Read);
            ICryptoTransform myICryptoTransform = myDESProvider.CreateDecryptor(myDESProvider.Key, myDESProvider.IV);
            CryptoStream myCryptoStream = new CryptoStream(DecryptedFile, myICryptoTransform, CryptoStreamMode.Read);
             StreamReader myDecStreamReader = new StreamReader(myCryptoStream);
            StreamWriter myDecStreamWriter = new StreamWriter("p1.txt");
              myDecStreamWriter.Write(myDecStreamReader.ReadToEnd());
              myCryptoStream.Close();
             myDecStreamReader.Close();
             myDecStreamWriter.Close();
         }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
}

4. Now convert the encrypted text file in the folder D:\New Folder (2)\ConsoleApplication4\ConsoleApplication4\bin\Debug (My text file path) to decrypted text file.

Now start debugging, you will see a testDes.txt file automatically converted into p1.text Decrypted text file.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor