Platforms to show: All Mac Windows Linux Cross-Platform

/Encryption/Threaded Encryption and Hashes


Required plugins for this example: MBS Encryption Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Encryption/Threaded Encryption and Hashes

This example is the version from Mon, 16th Jul 2017.

Project "Threaded Encryption and Hashes.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action() dim f as FolderItem = GetOpenFolderItem("") if f = nil then Return file = f RunThreadedButton.Enabled = true RunWithoutThreads.Enabled = true End EventHandler
End Control
Control list Inherits Listbox
ControlInstance list Inherits Listbox
EventHandler Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean dim c as new Clipboard c.SetText me.Cell(row, column) End EventHandler
End Control
Control RunThreadedButton Inherits PushButton
ControlInstance RunThreadedButton Inherits PushButton
EventHandler Sub Action() prepare // run each on a new thread Runthreaded AddressOf TestCipherAES Runthreaded AddressOf TestCipherBlowfish Runthreaded AddressOf TestDigestMD5 Runthreaded AddressOf TestDigestSHA512 Runthreaded AddressOf TestMD5 Runthreaded AddressOf TestSHA1 Runthreaded AddressOf TestSHA256 Runthreaded AddressOf TestSHA512 End EventHandler
End Control
Control RunWithoutThreads Inherits PushButton
ControlInstance RunWithoutThreads Inherits PushButton
EventHandler Sub Action() Prepare TestCipherAES TestCipherBlowfish TestDigestMD5 TestDigestSHA512 TestMD5 TestSHA1 TestSHA256 TestSHA512 End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() while ForList.Ubound>=0 dim v as Variant = ForList(0) ForList.Remove 0 // get array back from variant dim s() as string = v list.AddRow s wend if running and isDone then dim t as integer = ticks - LaunchTicks list.AddRow "All done", FormatTicks(t), "" running = false ProgressWheel1.Visible = false RunThreadedButton.Enabled = true RunWithoutThreads.Enabled = true redim Threads(-1) end if End EventHandler
End Control
Control ProgressWheel1 Inherits ProgressWheel
ControlInstance ProgressWheel1 Inherits ProgressWheel
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
EventHandler Sub Close() for each f as FolderItem in filesToDelete f.Delete next End EventHandler
Sub Add(paramArray s as string) // add new array of string to array of variants if app.CurrentThread = nil then // main thread list.AddRow s else // add later with timer ForList.Append s end if End Sub
Sub CheckNextThread() // launch more threads for each t as myThread in threads if not t.Started then t.Started = true t.run end if next End Sub
Function FormatTicks(t as integer) As string Return Format(t / 60.0, "0.0")+"s" End Function
Sub Prepare() LaunchTicks = ticks Running = true ProgressWheel1.Visible = true End Sub
Sub Runthreaded(t as ThreadFunc) dim thread as new myThread(T) if UBound(threads) < 4 then thread.Started = true thread.run end if threads.Append thread End Sub
Sub TestCipherAES() dim t as integer = ticks dim d as CipherMBS = CipherMBS.aes_256_cfb128 dim outfile as FolderItem = GetTemporaryFolderItem filesToDelete.append outfile dim CKey as MemoryBlock = "1234567812345678" dim CIV as MemoryBlock call d.EncryptInit Ckey, CIV if d.ProcessFile(file, outfile) then t = ticks - t Add "Cipher AES 256 CFB 128 encrypt", FormatTicks(t) else Add "Cipher AES 256 CFB 128 encrypt", "", "Failed." Return end if t = ticks d = CipherMBS.aes_256_cfb128 dim defile as FolderItem = GetTemporaryFolderItem filesToDelete.append defile call d.DecryptInit Ckey, CIV if d.ProcessFile(outfile, defile) then t = ticks - t Add "Cipher AES 256 CFB 128 decrypt", FormatTicks(t) else Add "Cipher AES 256 CFB 128 decrypt", "", "Failed." end if End Sub
Sub TestCipherBlowfish() dim t as integer = ticks dim d as CipherMBS = CipherMBS.bf_cfb64 dim outfile as FolderItem = GetTemporaryFolderItem filesToDelete.append outfile dim CKey as MemoryBlock = "1234567812345678" dim CIV as MemoryBlock call d.EncryptInit Ckey, CIV if d.ProcessFile(file, outfile) then t = ticks - t Add "Cipher Blowfish encrypt", FormatTicks(t) else Add "Cipher Blowfish encrypt", "", "Failed." Return end if t = ticks d = CipherMBS.bf_cfb64 dim defile as FolderItem = GetTemporaryFolderItem filesToDelete.append defile call d.DecryptInit Ckey, CIV if d.ProcessFile(outfile, defile) then t = ticks - t Add "Cipher Blowfish decrypt", FormatTicks(t) else Add "Cipher Blowfish decrypt", "", "Failed." end if End Sub
Sub TestDigestMD5() dim t as integer = ticks dim d as DigestMBS = DigestMBS.MD5 if d.Process(file) then dim h as string = d.FinalText t = ticks - t Add "Digest MD5", FormatTicks(t), h else Add "Digest MD5", "", "Failed." end if End Sub
Sub TestDigestSHA512() dim t as integer = ticks dim d as DigestMBS = DigestMBS.SHA512 if d.Process(file) then dim h as string = d.FinalText t = ticks - t Add "Digest SHA512", FormatTicks(t), h else Add "Digest SHA512", "", "Failed." end if End Sub
Sub TestMD5() dim h as string dim t as integer = ticks h = MD5DigestMBS.HashFile(file, true) t = ticks - t Add "MD5 HashFile", FormatTicks(t), h End Sub
Sub TestSHA1() dim h as string dim t as integer = ticks h = SHA1MBS.HashFile(file, true) t = ticks - t Add "SHA1 HashFile", FormatTicks(t), h End Sub
Sub TestSHA256() dim h as string dim t as integer = ticks h = SHA256MBS.HashFile(file, true) t = ticks - t Add "SHA256 HashFile", FormatTicks(t), h End Sub
Sub TestSHA512() dim h as string dim t as integer = ticks h = SHA512MBS.HashFile(file, true) t = ticks - t Add "SHA512 HashFile", FormatTicks(t), h End Sub
Function isDone() As Boolean if UBound(threads) = -1 then Return true end if for each t as myThread in threads if not t.started then Return false end if if t.state = t.Running then Return false end if next Return true End Function
Property ForList() As Variant
array of variants which will contain string arrays
Property LaunchTicks As Integer
Property Running As Boolean
Property file As FolderItem
Property filesToDelete() As FolderItem
Property threads() As myThread
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class myThread Inherits thread
EventHandler Sub Run() // run a function threaded t.Invoke t = nil MainWindow.CheckNextThread End EventHandler
Sub Constructor(f as ThreadFunc) t = f End Sub
Property Started As Boolean
Property t As ThreadFunc
End Class
Module Module1
Delegate Sub ThreadFunc()
End Module
End Project

The items on this page are in the following plugins: MBS Encryption Plugin.


The biggest plugin in space...