dOPC Client Toolkit
Close
ua.client.TdOPCUAClient.SecurityKeypair

Class property to handle public and private keys

property SecurityKeypair: TuaKeypair;
__property TuaKeypair SecurityKeypair;

This class is used in the TdOPCUAClient class to handle public and private keys for the security connect process. 

If you want to connect to a secure OPC UA server, which means you have set the property SecurityMode to a value <> None, then you must have a certificate. To create an OPC UA client certificate you can use e.g. our example program "..\ua-core\UACreateCert or e.g. OpenSSL. Click here to download an OpenSSL example script to create certificates for your OPC UA client programs. 

Once you have created a certificate, you can load the public and private keys into the component at run time or design time. 

At design time: 

To load the certificate at design time, you can use the property editor of the SecurityKeypair property. You can open this editor by double clicking on (TuaKeypair) or by clicking on the 3 dots (...) of the "SecurityKeypair" property. 

At runtime: 

To load the your certificate at run time you can use e.g. following methods:

dOPCUAClient.SecurityKeypair.Publickey.FromFile('c:\test\mypublickey.der'); dOPCUAClient.SecurityKeypair.Privatekey.FromFile('c:\test\myprivate.der');

Public and Private key are type of ByteString. This type is a normal string but has a helper class with following methods:

function ToBytes: TBytes; procedure ToFile(Filename: string); procedure ToStream(Stream: TStream); procedure FromBytes(Key: TBytes); procedure FromFile(FileName: string); procedure FromStream(Stream: TStream);
program SecureConnect; {$APPTYPE CONSOLE} {$R *.res} uses sysutils, ua.client, ua.datatypes, ua.buildintypes; var OPCClient: TdOPCUAClient; ProgPath : string; begin ProgPath := ExtractFilePath(Paramstr(0)); OPCClient := TdOPCUaClient.Create(nil); try OPCClient.SecurityMode := TuaSecurityMode.uaSSignAndEncrypt; OPCClient.SecurityPolicy := TuaSecurityPolicy.uaSPBasic256Sha256; OPCClient.Url := 'opc.tcp://localhost:53530/OPCUA/SimulationServer'; OPCClient.SecurityKeypair.LoadCertificateFromFile(ProgPath+'UACreateCert'); // load private and public key with one call { or also possible OPCClient.SecurityKeypair.PublicKey.FromFile (ProgPath+'UACreateCert.der'); OPCClient.SecurityKeypair.PrivateKey.FromFile (ProgPath+'UACreateCert.pem'); // with user authentication method OPCClient.UserLogin.SetUser('test','test'); // with certificate authentication method Please note: Only for test with same certificate OPCClient.UserLogin.LoginMode := TuaSecurityUser.Certificate; OPCClient.UserLogin.Keypair.LoadCertificateFromFile(ProgPath+'UACreateCert'); } OPCClient.Active := true; Writeln('connected :-)'); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; OPCClient.Free; Writeln('press any key to exit'); readln; end.
Kassl GmbH Copyright © 2024. All rights reserved.