BlowFish Class

J.C. SolvoTerra 0 Tallied Votes 1K Views Share

BlowFish?

BlowFish was the brain child of Bruce Schneier back in 93. Since BlowFish was released to the public domain, Bruce Schneier has released new encryption algorythems, TwoFish and ThreeFish. BlowFish is an increddibly popular and very strong algorythem. Because it conforms to Kerckhoffs's Principal Explained Here, even though the algorithem is public domain, it still isn't crackable without the key.

It Isn't Mine, I Just Converted It.

I'm far from a maths genius, far, far from it. My only involvement in this class is converting from VB6 and wrapping. I have tried to comment the parts of the algorithm that I understand, much beyond that I'm afraid you'll probably have a better understanding than I.

I have wrapped the class up nicely so there is little more then Encode, Decode and Key available to the user. I have also included as much error handling as possible.

Share and Share A-Like

There are many, many examples of BlowFish out there, in all kinds of languages, but not VB.Net. With that in mind, I decided to share this conversion so there is at least one VB.Net version out there... And where best to host it, but on DaniWeb. Obviousley in accordance to the aforementiond Kerckhoffs's principal, I'm not jeopardizing the security of this algorythem, however it may be worth playing around with the intialization values to ensure your Boxes are unique.

The code provided is a guide how you can use the Class. Very simple.

Jay

'EXAMPLE USAGE. Download Encryption.Zip for BlowFish Class

Imports System.IO

Public Class Form1

    Dim WithEvents BF As BlowFish
    Dim sFile As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        BF = New BlowFish()
        AddHandler BF.Terminated, AddressOf Terminated
        AddHandler BF.Progress, AddressOf Progress
        AddHandler BF.Complete, AddressOf Complete

    End Sub

    Private Sub Progress(Percent As Integer)

        Me.Text = Percent

    End Sub

    Private Sub Complete()

        Console.WriteLine(DateTime.Now & " : Complete")

    End Sub

    Private Sub Terminated(pError As String)

        Console.WriteLine(DateTime.Now & "TERMINATED : " & pError)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        'Encode

        Try
            BF.Key = System.Text.Encoding.UTF8.GetBytes("YOUR_KEY")

            Dim fBytes As Byte() = File.ReadAllBytes(sFile)
            Dim eBytes As Byte() = BF.EncodeBytes(fBytes)

            'Process\Save Encoded Bytes in eBytes

        Catch eX As Exception

            Console.WriteLine(eX.Message)

        End Try

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        'Decode

        Try
            BF.Key = System.Text.Encoding.UTF8.GetBytes("YOUR_KEY")

            Dim fBytes As Byte() = File.ReadAllBytes(sFile)
            Dim dBytes As Byte() = BF.DecodeBytes(fBytes)

            'Process\Save Decoded Bytes in dBytes

        Catch eX As Exception

            Console.WriteLine(eX.Message)

        End Try

    End Sub

End Class
zen_1 0 Newbie Poster

excuse me sir. may I ask you something about your program?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.