In the opc ua client from OPC foundation you can automatically create a self signed client certificate and accept the server certificate using this code:
SecurityConfiguration = new SecurityConfiguration
{
ApplicationCertificate = new CertificateIdentifier { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\OPC Foundation\CertificateStores\MachineDefault", SubjectName = "MyClient" },
TrustedIssuerCertificates = new CertificateTrustList { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\OPC Foundation\CertificateStores\UA Certificate Authorities" },
TrustedPeerCertificates = new CertificateTrustList { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\OPC Foundation\CertificateStores\UA Applications" },
RejectedCertificateStore = new CertificateTrustList { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\OPC Foundation\CertificateStores\RejectedCertificates" },
AutoAcceptUntrustedCertificates = true
},
application.CheckApplicationInstanceCertificate(false, 2048).GetAwaiter().GetResult();
You can also specify which certificate (a custom certificate) to use by changing the SubjectName to the CN of the certificate you want to use. Just make sure you put the private key in the private folder.
If you put the second parameter on true it will use security (certificates) when connection to your server.
var selectedEndpoint = CoreClientUtils.SelectEndpoint("opc.tcp://" + ip + ":" + port, true);