本文介绍了OPC UA错误:无法将自签名证书添加到证书存储区。我如何解决它并使用OPC.UA命名空间为tcp / ip连接创建clientCertificate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建客户端Cirtificate时出现错误:

There is an Error When i am creating a client Cirtificate:

Could not add self-signed certificate to certficate store.





我使用以下命名空间



I am using the following Namespace:

using System;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
using System.Linq;
using Opc.Ua;





我的代码是:



My code is:

public static ApplicationConfiguration CreateClientConfiguration()
       {
          ApplicationConfiguration configuration = new ApplicationConfiguration();

           configuration.ApplicationName = "UA AC Test Client";
           configuration.ApplicationType = ApplicationType.Client;
           configuration.ApplicationUri = "http://localhost/VendorId/ApplicationId/InstanceId";
           configuration.ProductUri = "http://VendorId/ProductId/VersionId";

           configuration.SecurityConfiguration = new SecurityConfiguration();
configuration.SecurityConfiguration.ApplicationCertificate = new CertificateIdentifier();
           configuration.SecurityConfiguration.ApplicationCertificate.StoreType = CertificateStoreType.Windows;
           configuration.SecurityConfiguration.ApplicationCertificate.StorePath = "LocalMachine\\My";
           configuration.SecurityConfiguration.ApplicationCertificate.SubjectName = configuration.ApplicationName;

           configuration.SecurityConfiguration.TrustedPeerCertificates.StoreType = CertificateStoreType.Windows;
           configuration.SecurityConfiguration.TrustedPeerCertificates.StorePath = "LocalMachine\\My";

           X509Certificate2 clientCertificate = configuration.SecurityConfiguration.ApplicationCertificate.Find(true);
           try
           {
               // create a new certificate if one not found.
               if (clientCertificate == null)
               {
                   clientCertificate = CertificateFactory.CreateCertificate(
                   configuration.SecurityConfiguration.ApplicationCertificate.StoreType,
                   configuration.SecurityConfiguration.ApplicationCertificate.StorePath,
                   configuration.ApplicationUri,
                   configuration.ApplicationName,
                   null,
                   null,
                   1024,
                   120);
               }
           }
           catch (Exception e)
           {
           }
           configuration.TransportConfigurations.Add(new                   TransportConfiguration(Utils.UriSchemeOpcTcp, typeof(Opc.Ua.Bindings.UaTcpBinding)));
           configuration.TransportConfigurations.Add(new    TransportConfiguration(Utils.UriSchemeHttp, typeof(Opc.Ua.Bindings.UaSoapXmlBinding)));
           configuration.TransportQuotas = new TransportQuotas();
           configuration.TransportQuotas.OperationTimeout = 360000;
           configuration.TransportQuotas.MaxStringLength = 67108864;
           configuration.ServerConfiguration = new ServerConfiguration();

           configuration.ClientConfiguration = new ClientConfiguration();
           configuration.ClientConfiguration.DefaultSessionTimeout = 360000;

           configuration.Validate(ApplicationType.Client);

           return configuration;
       }





请帮忙解决。



please help to solve it.

推荐答案



这篇关于OPC UA错误:无法将自签名证书添加到证书存储区。我如何解决它并使用OPC.UA命名空间为tcp / ip连接创建clientCertificate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:58