Private Key missing in X509Certificate2 after creating certificate #2703
-
Hi Team, The following code which was copied from UA.NETStandard 1.4.366.38 method CertificateFactory.CreateCertificate works correctly with OPCFoundation.NetStandard.Opc.Ua 1.4.370.12 but NOT with OPCFoundation.NetStandard.Opc.Ua 1.4.371.86 and later versions. The resulting X509Certificate2 certificate from method call “createBuilder.CreateForRSA();” does not contain private key despite HasPrivateKey property is true and PrivateKey property is null. Is this some bug in OPCFoundation.NetStandard.Opc.Ua or is there any other way to create certificate including private key? private static X509Certificate2 CertificateFactoryCreateCertificate(string applicationUri, string applicationName, string subjectName, IList domainNames, ushort keySize, DateTime startTime, ushort lifetimeInMonths, ushort hashSizeInBits, bool isCA = false, X509Certificate2 issuerCAKeyCert = null, byte[] publicKey = null, int pathLengthConstraint = 0)
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
hi @ahmadjqureshi , which platform are you using? windows or linux? .NET 8 or .NET Framework? |
Beta Was this translation helpful? Give feedback.
Hi @ahmadjqureshi, in your case bouncy castle is not used to create a certificate, on .NET Framework 4.8 bc is just used for PEM import/export. Also .NET Framework 4.8 supports the ephemeral keyset. The new certificate has a private key, but it may require a reload to use crypto, but I may not remember correctly.
the PrivateKey property is not used to access the private key. To access the private key you would: