Share via

Creating X509Certificate from PKCS #12 store failed

Dario Galvani 6 Reputation points
Oct 21, 2022, 1:37 PM

Hi all,
I'm newbie with MAUI. I've a test app developed with MAUI to write/read values via OPC (PLC Enviroment).
If I test the app with emulator everything works good.
If I test the app on the phisical device (android phone) I get this exception (below)

{System.NotSupportedException: Creating X509Certificate from PKCS #12 store failed
---> System.PlatformNotSupportedException: The PKCS#12 PersistKeySet flag is not supported on this platform.
at Internal.Cryptography.Pal.AndroidCertificatePal.FromBlob(ReadOnlySpan1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at Internal.Cryptography.Pal.CertificatePal.FromBlob(ReadOnlySpan1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
at CertificateFactory.a(Byte[] a, String b, Nullable1 c) at CertificateFactory.CreateCertificateFromPKCS12(Byte[] rawData, String password) --- End of inner exception stack trace --- at CertificateFactory.CreateCertificateFromPKCS12(Byte[] rawData, String password) at CertificateFactory.a(X509Certificate a, String b, AsymmetricKeyParameter c, SecureRandom d) at CertificateFactory.CreateCertificate(String storeType, String storePath, String password, String applicationUri, String applicationName, String subjectName, IList1 domainNames, UInt16 keySize, DateTime startTime, UInt16 lifetimeInMonths, UInt16 hashSizeInBits, Boolean isCA, X509Certificate2 issuerCAKeyCert, Byte[] publicKey)
at Opc.UaFx.OpcCertificateManager.CreateCertificate(OpcCertificateSettings settings, OpcCertificateStoreInfo store)
at Opc.UaFx.OpcCertificateManager.CreateCertificate(IOpcApplicationInstance instance, OpcCertificateStoreInfo store)
at Opc.UaFx.OpcCertificateStores.a()
at Opc.UaFx.OpcCertificateStores.a()
at Opc.UaFx.OpcApplicationInstance`2[[Opc.UaFx.OpcTransport, Opc.UaFx.Client, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0220af0d33d50236],[Opc.UaFx.Client.OpcClientSecurity, Opc.UaFx.Client, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0220af0d33d50236]].Setup(OpcApplicationConfiguration configuration)
at Opc.UaFx.Client.OpcClient.Connect()

I'm too newbie to understand if this is a problem of Android configuration, app issue or (my nightmare) opcfx trouble.

I've surfed on the net but I found answers too much different

So, I'm here to ask you if someone can help me to understand this issue so I could solve it.

TIA
Dario

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,042 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.