Hi all this is a new example this uses the built in TripleDES functions in VB.NET this example has a class and an example. The class allows you to encrypt decrypt files with a password.
It also has two string functions for encrypting and decrypting strings.
Hope you find this of some use. comments and suggestions welcome.

class code cDes.vb

vbnet Code:
  1. 'TripleDES encrypter / Decrypter for files and strings.
  2. 'This example is part of Bens Jones encryption codes use as you like.
  3.  
  4. Option Explicit On
  5.  
  6. Imports System.Security.Cryptography
  7. Imports System.Text
  8. Imports System.IO
  9.  
  10. Public Class cDes
  11.  
  12.     'Class variables.
  13.     Private m_Input As String = vbNullString
  14.     Private m_Output As String = vbNullString
  15.     Private m_Password As String = vbNullString
  16.  
  17.     Public Property InputFile As String
  18.         Get
  19.             Return m_Input
  20.         End Get
  21.         Set(ByVal value As String)
  22.             m_Input = value
  23.         End Set
  24.     End Property
  25.  
  26.     Public Property OutputFile As String
  27.         Get
  28.             Return m_Output
  29.         End Get
  30.         Set(ByVal value As String)
  31.             m_Output = value
  32.         End Set
  33.     End Property
  34.  
  35.     Public Property Password As String
  36.         Get
  37.             Return m_Password
  38.         End Get
  39.         Set(ByVal value As String)
  40.             m_Password = value
  41.         End Set
  42.     End Property
  43.  
  44.     Public Sub DecryptFile()
  45.         'Decrypt file.
  46.         DoAction(False)
  47.     End Sub
  48.  
  49.     Public Sub EncryptFile()
  50.         'Encrypt file.
  51.         DoAction(True)
  52.     End Sub
  53.  
  54.     Public Function EncryptString(ByVal source As String, ByVal Password As String) As String
  55.         Dim Bytes() As Byte
  56.  
  57.         Dim Des As New TripleDESCryptoServiceProvider()
  58.         Dim Hash As New MD5CryptoServiceProvider()
  59.         Dim EnTransForm As ICryptoTransform = Nothing
  60.  
  61.         Try
  62.             'Create encrypter.
  63.             Des.Key = Hash.ComputeHash(Encoding.ASCII.GetBytes(Password))
  64.             Des.Mode = CipherMode.ECB
  65.             EnTransForm = Des.CreateEncryptor()
  66.             'Get bytes from string.
  67.             Bytes = Encoding.ASCII.GetBytes(source)
  68.             'Return base64 string.
  69.             Return Convert.ToBase64String(EnTransForm.TransformFinalBlock(Bytes, 0, Bytes.Length))
  70.         Catch ex As Exception
  71.             Throw New ArgumentException(ex.Message)
  72.         End Try
  73.     End Function
  74.  
  75.     Public Function DecryptString(ByVal source As String, ByVal Password As String) As String
  76.         Dim Bytes() As Byte
  77.  
  78.         Dim Des As New TripleDESCryptoServiceProvider()
  79.         Dim Hash As New MD5CryptoServiceProvider()
  80.         Dim EnTransForm As ICryptoTransform = Nothing
  81.  
  82.         Try
  83.             'Create decrypter.
  84.             Des.Key = Hash.ComputeHash(Encoding.ASCII.GetBytes(Password))
  85.             Des.Mode = CipherMode.ECB
  86.             EnTransForm = Des.CreateDecryptor()
  87.             'Get bytes from string.
  88.             Bytes = Convert.FromBase64String(source)
  89.             'Return string.
  90.             Return Encoding.ASCII.GetString(EnTransForm.TransformFinalBlock(Bytes,0,Bytes.Length))
  91.         Catch ex As Exception
  92.             Throw New ArgumentException(ex.Message)
  93.         End Try
  94.     End Function
  95.  
  96.     Private Sub DoAction(ByVal Encrypt As Boolean)
  97.         Dim br As BinaryReader = Nothing
  98.         Dim bw As BinaryWriter = Nothing
  99.         Dim Bytes() As Byte
  100.  
  101.         Dim Des As New TripleDESCryptoServiceProvider()
  102.         Dim Hash As New MD5CryptoServiceProvider()
  103.         Dim EnTransForm As ICryptoTransform = Nothing
  104.  
  105.         'Check for password.
  106.         If String.IsNullOrWhiteSpace(Password) Then
  107.             Throw New ArgumentException("No Password Found")
  108.         End If
  109.  
  110.         Try
  111.             br = New BinaryReader(File.OpenRead(InputFile))
  112.             'Create hash from password.
  113.             Des.Key = Hash.ComputeHash(Encoding.ASCII.GetBytes(Password))
  114.             'Set mode.
  115.             Des.Mode = CipherMode.ECB
  116.  
  117.             If Encrypt Then
  118.                 'Create encrypter.
  119.                 EnTransForm = Des.CreateEncryptor()
  120.             Else
  121.                 'Create decrypter.
  122.                 EnTransForm = Des.CreateDecryptor()
  123.             End If
  124.  
  125.             'Read bytes from input filename.
  126.             Bytes = br.ReadBytes(br.BaseStream.Length)
  127.             'Encrypt bytes.
  128.             Bytes = EnTransForm.TransformFinalBlock(Bytes, 0, Bytes.Length)
  129.             'Create output filename.
  130.             bw = New BinaryWriter(File.OpenWrite(OutputFile))
  131.             'Write bytes to output file.
  132.             bw.Write(Bytes)
  133.  
  134.             'Close open files.
  135.             bw.Close()
  136.             br.Close()
  137.         Catch ex As Exception
  138.             Throw New ArgumentException(ex.Message)
  139.         End Try
  140.     End Sub
  141. End Class

Examples

vbnet Code:
  1. Public Class Form1
  2.  
  3.     Private Sub cmdTest1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest1.Click
  4.         Dim MyDes As New cDes()
  5.  
  6.         With MyDes
  7.             'Set password for encrypting and decrypting.
  8.             .Password = "crimson"
  9.  
  10.             Try
  11.                 'Encrypt file.
  12.                 .InputFile = "C:\out\data\test.txt"
  13.                 .OutputFile = "C:\out\data\out.txt"
  14.                 .EncryptFile()
  15.                 'Decrypt file.
  16.                 .InputFile = "C:\out\data\out.txt"
  17.                 .OutputFile = "C:\out\data\new.txt"
  18.                 .DecryptFile()
  19.             Catch ex As Exception
  20.                 MessageBox.Show(ex.Message, "Error",
  21.                                 MessageBoxButtons.OK, MessageBoxIcon.Error)
  22.             End Try
  23.         End With
  24.     End Sub
  25.  
  26.     Private Sub cmdTest2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest2.Click
  27.         Dim MyDes As New cDes()
  28.         Dim Demo As String = "Hello World"
  29.  
  30.         'Original
  31.         MessageBox.Show("Original: " & Demo, "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information)
  32.  
  33.         'Encrypt string
  34.         Demo = MyDes.EncryptString(Demo, "alpha45")
  35.         MessageBox.Show("Encrypted: " & Demo, "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information)
  36.  
  37.         'Decrypt string
  38.         Demo = MyDes.DecryptString(Demo, "alpha45")
  39.         MessageBox.Show("Decrypted: " & Demo, "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information)
  40.     End Sub
  41. End Class