Decrypt the Encrypted text File in VB.Net: Part 2

In this tutorial we will learn how to decrypt a Encrypted text file in VB.Net.
  • 5702
 

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.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.