Use DES to Decrypt a file : DES « Security « VB.Net Tutorial






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


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("testDes.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("test.txt")

            myDecStreamWriter.Write(myDecStreamReader.ReadToEnd())

            myCryptoStream.Close()
            myDecStreamReader.Close()
            myDecStreamWriter.Close()
        Catch ex As Exception

            Console.WriteLine(ex.ToString())
        End Try
    End Sub
End Class








21.1.DES
21.1.1.DES Encrypt/Decrypt
21.1.2.Use DES to encrypt a file
21.1.3.Use DES to Decrypt a file