Platforms to show: All Mac Windows Linux Cross-Platform

/Encryption/Blowfish OpenSSL Tests
Function:
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 2017.
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 -a -v -p -salt -in "+InputPath+" -out "+OutputPath+" -pass ""pass:"+pass+"""" 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 'MsgBox r DecryptedOpenPlugin.text = 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 -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 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 call c.EncryptInit Ckey, CIV dim output as string = c.ProcessString(data) output = output + c.FinalizeAsString output = salted+salt+output output = EncodeBase64(output, 0) EncryptedPlugin.Text = output end if 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 call c.DecryptInit Ckey, CIV dim output as string = 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 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:

Feedback, Comments & Corrections

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

The biggest plugin in space...




Links
MBS Xojo PDF Plugins

Start Chat