ARTICLE

How we Decrypt the Encrypted text File using DES method in VB.Net: Part 2

Posted by Brijesh Jalan Articles | Cryptography in VB.NET August 16, 2010
In this tutorial we will learn how to decrypt a Encrypted text file in VB.Net.
 
Reader Level:

Click here for Part 1

1.Open visual studio and create a project

2.Add the following assembly on the page

Imports System.Security
Imports
System.Security.Cryptography
Imports
System.Text
Imports
System.IO

3.Now write the Code in the Page

Public Class Tester
    Public Shared Sub Main()
        Try
            Dim myDESProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
             myDESProvider.Key = ASCIIEncoding.ASCII.GetBytes("12345678")
            myDESProvider.IV = ASCIIEncoding.ASCII.GetBytes("12345678")
             Dim DecryptedFile As FileStream = New FileStream("Encrypted.txt", FileMode.Open, FileAccess.Read)
            Dim myICryptoTransform As ICryptoTransform = myDESProvider.CreateDecryptor(myDESProvider.Key, myDESProvider.IV)
            Dim myCryptoStream As CryptoStream = New CryptoStream(DecryptedFile, myICryptoTransform, CryptoStreamMode.Read)
             Dim myDecStreamReader As New StreamReader(myCryptoStream)
            Dim myDecStreamWriter As New StreamWriter("Decrypted.txt")
             myDecStreamWriter.Write(myDecStreamReader.ReadToEnd())
             myCryptoStream.Close()
            myDecStreamReader.Close()
            myDecStreamWriter.Close()
        Catch ex As Exception
             Console.WriteLine(ex.ToString())
        End Try
        Console.ReadLine()
    End Sub

End
Class

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

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

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • 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.
    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.
Nevron Diagram
Become a Sponsor