Lee Tickett
Lee Tickett

Reputation: 6037

CryptographicException- Invalid provider type specified when accessing Xero API

The code causing this is;

            //Authorise
            System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(Server.MapPath("cert\\xero.pfx"), "xero");
            var private_app_api =
                new XeroCoreApi("https://api.xero.com/api.xro/2.0/",
                new PrivateAuthenticator(cert),
                new Consumer(ConfigurationManager.AppSettings["xero_consumer_key"], ConfigurationManager.AppSettings["xero_consumer_secret"]),
                null,
                new DefaultMapper(),
                new DefaultMapper());
                Xero.Api.Core.Model.Contact contact = private_app_api.Contacts.Find("c12e9f0e-3c12-4b63-91ef-b027c237dd35");

The code is in a asp.net application running on an app pool as a local user account.

Here are the error details;

Exception information: 
    Exception type: CryptographicException 
    Exception message: Invalid provider type specified.

   at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
   at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
   at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
   at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
   at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
   at Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.Sign(SHA1CryptoServiceProvider hash)
   at Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.SignCore(String baseString)
   at Xero.Api.Infrastructure.OAuth.Signing.RsaSha1Signer.CreateSignature(X509Certificate2 certificate, IToken token, Uri uri, String verb, String verifier, Boolean renewToken, String callback)
   at Xero.Api.Example.Applications.Private.PrivateAuthenticator.GetSignature(IConsumer consumer, IUser user, Uri uri, String verb, IConsumer consumer1)
   at Xero.Api.Infrastructure.Http.HttpClient.CreateRequest(String endPoint, String method, String accept, String query)
   at Xero.Api.Infrastructure.Http.HttpClient.Get(String endpoint, String query)
   at Xero.Api.Infrastructure.Http.XeroHttpClient.Get[TResult,TResponse](String endPoint)
   at Xero.Api.Common.XeroReadEndpoint`3.Get(String endpoint, String child)
   at Xero.Api.Common.XeroReadEndpoint`3.Find(String child)
   at Xero.Api.Common.XeroReadEndpoint`3.Find(Guid child)
   at Register.Invoicing.b_create_invoices_Click(Object sender, EventArgs e) in C:\SVN\Circles\RegistrationSystem\Register\Register\Invoicing.aspx.cs:line 203
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Upvotes: 1

Views: 3912

Answers (1)

Lee Tickett
Lee Tickett

Reputation: 6037

The error went away when I set "Enable 32-Bit Applications" to true on the app pool. I find it confusing why it works when set to false but running the app pool as a user with administrative permissions?

I'd love a better explanation of what's going on.

Upvotes: 1

Related Questions