DES Encrypt/Decrypt : DES « Security « VB.Net Tutorial






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


Public Class Tester
    Public Shared Sub Main
            'Dim str As String = "1234567890asdfgh"
            'must be exactly 16 characters long

            Dim sSource, sKey, sIV, sResult As String
            sSource = "string"
            Dim objDES As New DESCryptoServiceProvider()
            Dim objStream As New MemoryStream(ASCII.GetBytes(sSource), False)

            sKey = "12345678"
            sIV = "12345678"

            objDES.IV = ASCII.GetBytes(sIV)
            objDES.Key = ASCII.GetBytes(sKey)

            sResult = ASCII.GetChars(objDES.CreateEncryptor().TransformFinalBlock(ASCII.GetBytes(sSource), 0, sSource.Length))
            Console.WriteLine(sResult)
            'sResult = ASCII.GetChars(objDES.CreateDecryptor().TransformFinalBlock(ASCII.GetBytes(sSource), 0, sSource.Length))
            'Console.WriteLine(sResult)
    
    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