Click here to Skip to main content
15,846,038 members
Please Sign up or sign in to vote.
3.15/5 (3 votes)
See more:
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.
Posted
Updated 4-Mar-13 1:19am
v2

I'm not sure, but I think this is a part of Beckhoff OPC UA Example...
You just have to start Visual Studio as an administrator to be able to create OPC certificates properly. That's all :-)
 
Share this answer
 
v2
I have the same problem.
How did you solve this?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900