Platforms to show: All Mac Windows Linux Cross-Platform

/Encryption/ECKey/ECKey Server


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/ECKey/ECKey Server

This example is the version from Mon, 27th Dec 2020.

Project "ECKey Server.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class ServerWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() // send something to all active sockets Dim sockets() As TCPSocket = sock.ActiveConnections For Each sock As Variant In sockets Dim c As ConnectionSocket = sock If c.EncryptionInitialized Then Dim now As New date c.Write now.SQLDateTime+" at server" End If Next End EventHandler
End Control
EventHandler Sub Open() sock = New MyServerSocket sock.list = list sock.port = 9999 sock.MaximumSocketsConnected = 10 sock.MinimumSocketsAvailable = 3 sock.listen Log "Listening..." End EventHandler
Sub log(s as string) list.AddRow s End Sub
Property sock As MyServerSocket
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class ConnectionSocket Inherits TCPSocket
EventHandler Sub Connected() Log "ConnectionSocket Connected to "+Me.RemoteAddress Dim EC_Curve_ID As Integer = 415 // NID_X9_62_prime256v1 // on Server dhs = New ECDHEMBS(EC_Curve_ID) PublicKey = dhs.PublicKey // send public key to other side Me.Write PublicKey End EventHandler
EventHandler Sub DataAvailable() Dim data As String = Me.ReadAll If bf = Nil Then // setup encryption // on Server Dim secret As String = dhs.DeriveSecretKey(data) bf = New BlowfishMBS bf.SetKey secret EncryptionInitialized = True Else // got data, so decrypt it data = bf.DecryptCFB64(data, tempd) Process data End If End EventHandler
EventHandler Sub Error() Log "ConnectionSocket error: "+Str(me.LastErrorCode) End EventHandler
Sub Process(data as string) // do something useful here for data you got. Log "Received: "+data End Sub
Sub Write(data as string) // if we have encryption, apply it If bf <> Nil Then data = bf.EncryptCFB64(data, tempe) End If // Calling the overridden superclass method. Super.Write data End Sub
Sub log(s as string) list.AddRow s End Sub
Property EncryptionInitialized As Boolean
Property PublicKey As string
Property bf As BlowfishMBS
Property dhs As ECDHEMBS
Property list As listbox
Property tempd As MemoryBlock
Property tempe As MemoryBlock
End Class
Class MyServerSocket Inherits ServerSocket
EventHandler Function AddSocket() As TCPSocket Dim c As New ConnectionSocket c.list = list Return c End EventHandler
EventHandler Sub Error(ErrorCode as Integer) Log "ServerSocket error: "+Str(ErrorCode) End EventHandler
Sub log(s as string) list.AddRow s End Sub
Property list As listbox
End Class
End Project

See also:

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


The biggest plugin in space...