title: Xamarin.Android - RSACryptoServiceProvider CspParameters are null and CryptoKeySecurity is null using X509Certificate2
body: <p>can't find why my <code>RSACryptoServiceProvider</code> returning <code>null</code> values and <code>null</code> <code>CryptoKeySecurity</code> using <code>X509Certificate2</code> and <code>CspParameters</code> for provider <code>"Microsoft Enhanced RSA and AES Cryptographic Provider"</code>.</p>
  
  <p>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.</p>
  
  <p>Here is code I'm using:</p>
  
  <pre><code>private RSACryptoServiceProvider ComputeKey()
      {
          var certificateCollection = new X509Certificate2Collection();
          certificateCollection.Import(Data, Password, KeyStorageFlags);
          foreach (var certificate in certificateCollection)
          {
              if (!certificate.HasPrivateKey)
              {
                  continue;
              }
  
              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);
              result.ImportParameters(exportParameters);
              return result;
          }
  
          throw new ArgumentException("The provided certificate does not have any private keys.");
      }
  </code></pre>
  
  <p>Here is android result:
  <a href="https://i.stack.imgur.com/ddNn3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ddNn3.png" alt="android result"></a></p>
  
  <p>And here is working windows result:</p>
  
  <p><a href="https://i.stack.imgur.com/WdG3o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WdG3o.png" alt="windows result"></a></p>