Forum Xamarin.Android

RSACryptoServiceProvider CspParameters are null and CryptoKeySecurity is null using X509Certificate2

KastaKasta CZMember ✭✭

Hi guys,
can't find why my RSACryptoServiceProvider returning null values and null CryptoKeySecurity using X509Certificate2 and CspParameters for provider "Microsoft Enhanced RSA and AES Cryptographic Provider".

This code works well on Windows application and signs correctly, but on Xamarin.Android I can't figure out what is wrong. Any help would be nice.

Here is code I'm using:

private RSACryptoServiceProvider ComputeKey()
        var certificateCollection = new X509Certificate2Collection();
        certificateCollection.Import(Data, Password, KeyStorageFlags);
        foreach (var certificate in certificateCollection)
            if (!certificate.HasPrivateKey)

            var key = certificate.PrivateKey as RSACryptoServiceProvider;
            var exportParameters = key.ExportParameters(includePrivateParameters: true);
            var cspParameters = new CspParameters
                ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider",
                Flags = UseMachineKeyStore ? CspProviderFlags.UseMachineKeyStore : CspProviderFlags.NoFlags
            var result = new RSACryptoServiceProvider(cspParameters);
            return result;

        throw new ArgumentException("The provided certificate does not have any private keys.");

Here is android result:

And here is working windows result:


  • KastaKasta CZMember ✭✭

    Still can't find solution ... can anyone help me please?

Sign In or Register to comment.