I have a C# application that works on Windows, but when I try to run this on Linux using Mono I get this error:
System.DllNotFoundException: NCrypt
at (wrapper managed-to-native) PInvoke.NCrypt.NCryptOpenStorageProvider(PInvoke.NCrypt/SafeProviderHandle&,string,PInvoke.NCrypt/NCryptOpenStorageProviderFlags)
at PInvoke.NCrypt.NCryptOpenStorageProvider (System.String providerName, PInvoke.NCrypt+NCryptOpenStorageProviderFlags flags) [0x00000]
at PCLCrypto.NCryptAsymmetricKeyProviderBase.ImportPublicKey (System.Byte[] keyBlob, PCLCrypto.CryptographicPublicKeyBlobType blobType)
This is called via:
var rsa = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaPkcs1);
How do I fix?
This library, or at least the specific API you are using, appears to be using platform invoke to use Windows-specific libraries that are part of the operating system (CNG's ncrypt.dll). It does not appear it will work on non-Windows platforms.
You should use an alternative library that supports the cryptographic functions you are trying to use on the platform required.