Platforms to show: All Mac Windows Linux Cross-Platform

/Encryption/Blowfish OpenSSL Tests


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/Blowfish OpenSSL Tests

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

Project "Blowfish OpenSSL Tests.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control InputText Inherits TextField
ControlInstance InputText Inherits TextField
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control InputKey Inherits TextField
ControlInstance InputKey Inherits TextField
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control EncryptedOpenSSL Inherits TextArea
ControlInstance EncryptedOpenSSL Inherits TextArea
End Control
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action() run End EventHandler
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control DecryptedOpenSSL Inherits TextArea
ControlInstance DecryptedOpenSSL Inherits TextArea
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control DecryptedOpenPlugin Inherits TextArea
ControlInstance DecryptedOpenPlugin Inherits TextArea
End Control
Control EncryptedPlugin Inherits TextArea
ControlInstance EncryptedPlugin Inherits TextArea
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
EventHandler Sub Open() run End EventHandler
Protected Sub Run() Run1 run2 Run3 Run4 End Sub
Protected Sub Run1() Dim s As New shell Dim InputFile As FolderItem = GetTemporaryFolderItem Dim OutputFile As FolderItem = GetTemporaryFolderItem Dim b As BinaryStream = BinaryStream.Create(InputFile, True) b.Write ConvertEncoding(InputText.Text, encodings.UTF8) b.Close Dim InputPath As String = InputFile.ShellPath Dim OutputPath As String = OutputFile.shellpath Dim pass As String = ConvertEncoding(InputKey.Text, encodings.UTF8) pass = ReplaceAll(pass, """", "\""") s.Execute "openssl bf -bf-cbc -md md5 -a -v -p -salt -in "+InputPath+" -out "+OutputPath+" -pass ""pass:"+pass+"""" // -debug" b = BinaryStream.Open(OutputFile) EncryptedOpenSSL.Text = b.Read(b.Length, encodings.ASCII) b.Close InputFile.Delete OutputFile.Delete Dim r As String = s.Result If r.Len>0 Then DecryptedOpenPlugin.Text = r System.DebugLog r End If End Sub
Protected Sub Run2() Dim s As New shell Dim InputFile As FolderItem = GetTemporaryFolderItem Dim OutputFile As FolderItem = GetTemporaryFolderItem Dim b As BinaryStream = BinaryStream.Create(InputFile, True) b.Write ConvertEncoding(EncryptedOpenSSL.Text, encodings.UTF8) b.Close Dim InputPath As String = InputFile.ShellPath Dim OutputPath As String = OutputFile.shellpath Dim pass As String = ConvertEncoding(InputKey.Text, encodings.UTF8) pass = ReplaceAll(pass, """", "\""") s.Execute "openssl bf -bf-cbc -md md5 -d -a -salt -in "+InputPath+" -out "+OutputPath+" -pass ""pass:"+pass+"""" b = BinaryStream.Open(OutputFile) DecryptedOpenSSL.Text = b.Read(b.Length, encodings.utf8) b.Close InputFile.Delete OutputFile.Delete Dim r As String = s.Result If r.Len>0 Then System.DebugLog r MsgBox r End If End Sub
Protected Sub Run3() Dim s As String = DecodeBase64(EncryptedOpenSSL.Text) // 1. 8 byte: Salted__ // 2. 8 byte: Salt Dim salted As String = LeftB(s,8) Dim salt As String = MidB(s, 9, 8) Dim data As String = ConvertEncoding(InputText.Text, encodings.UTF8) Dim key As String = ConvertEncoding(InputKey.Text, encodings.UTF8) Dim c As CipherMBS = CipherMBS.bf_cbc Dim CKey As MemoryBlock Dim CIV As MemoryBlock If c.BytesToKey(c, DigestMBS.MD5, salt, key, 1, CKey, CIV) Then Dim output As String Call c.EncryptInit Ckey, CIV output = c.ProcessString(data) output = output + c.FinalizeAsString output = salted+salt+output output = EncodeBase64(output, 0) EncryptedPlugin.Text = output End If Exception r As RuntimeException // ignore End Sub
Protected Sub Run4() Dim s As String = DecodeBase64(EncryptedOpenSSL.Text) // 1. 8 byte: Salted__ // 2. 8 byte: Salt Dim salted As String = LeftB(s,8) Dim salt As String = MidB(s, 9, 8) Dim data As String = MidB(s, 17) Dim key As String = ConvertEncoding(InputKey.Text, encodings.UTF8) Dim c As CipherMBS = CipherMBS.bf_cbc Dim CKey As MemoryBlock Dim CIV As MemoryBlock If c.BytesToKey(c, DigestMBS.MD5, salt, key, 1, CKey, CIV) Then Dim output As String Call c.DecryptInit Ckey, CIV output = c.ProcessString(data) output = output + c.FinalizeAsString If Encodings.UTF8.IsValidData(output) Then output = DefineEncoding(output, Encodings.UTF8) Else output = DefineEncoding(output, encodings.ISOLatin1) End If DecryptedOpenPlugin.Text = output End If Exception r As RuntimeException // ignore End Sub
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
End Project

See also:

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


The biggest plugin in space...