CryptographicException-访问Xero API时指定的提供程序类型无效

时间:2017-09-23 21:55:53

标签: c# asp.net cryptography xero-api

造成这种情况的代码是;

            //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");

代码位于作为本地用户帐户在应用程序池上运行的asp.net应用程序中。

  • 如果我将应用池更改为以本地管理员身份运行,则错误就会消失。

  • 如果我将相同的代码放在控制台应用程序中,并且"运行为"应用程序池运行的本地用户帐户相同,因为我没有收到错误。

  • 流程监控器不会突出显示任何问题。

以下是错误详情;

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)

1 个答案:

答案 0 :(得分:1)

当我设置"启用32位应用程序&#34时,错误就消失了。在应用程序池上为true。我觉得这很困惑,为什么它设置为false时工作,但作为具有管理权限的用户运行应用程序池?

我喜欢更好地解释正在发生的事情。