- csharp/
- C# CryptographicException-访问Xero API时指定的提供程序类型无效
C# CryptographicException-访问Xero API时指定的提供程序类型无效
C# CryptographicException-访问Xero API时指定的提供程序类型无效,c#,asp.net,cryptography,xero-api,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 =
导致这种情况的代码是
//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");
//授权
System.Security.Cryptography.X509Certificates.X509Certificate2 cert=new System.Security.Cryptography.X509Certificate2(Server.MapPath(“cert\\xero.pfx”),“xero”);
var私有应用程序api=
新Xerocorapi(“https://api.xero.com/api.xro/2.0/",
新的私用验证器(cert),
新使用者(ConfigurationManager.AppSettings[“xero_使用者密钥”]、ConfigurationManager.AppSettings[“xero_使用者密钥”]),
无效的
新的DefaultMapper(),
新的DefaultMapper());
Xero.Api.Core.Model.Contact Contact=private_app_Api.Contacts.Find(“c12e9f0e-3c12-4b63-91ef-b027c237dd35”);
代码位于作为本地用户帐户在应用程序池上运行的asp.net应用程序中
- 如果我将应用程序池更改为以本地管理员身份运行,错误就会消失
- 如果我在控制台应用程序中放置相同的代码,并且“以”相同的本地用户帐户运行,则应用程序池正在运行,因为我没有收到错误
- Process monitor不会突出显示任何问题
以下是错误详细信息
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)
例外信息:
异常类型:加密异常
异常消息:指定的提供程序类型无效。
在System.Security.Cryptography.Utils.CreateProvHandle(CspParameters参数,布尔随机密钥容器)
在System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType、CspParameters parameters、Boolean randomKeyContainer、Int32 dwKeySize、SafeProvHandle和SafeProvHandle、SafeKeyHandle和SafeKeyHandle)
在System.Security.Cryptography.rsacyptoServiceProvider.GetKeyPair()中
在System.Security.Cryptography.RSACryptServiceProvider..ctor(Int32 dwKeySize、CspParameters、Boolean useDefaultKeySize)
在System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()中
位于Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.Sign(SHA1CryptoServiceProvider散列)
位于Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.SignCore(字符串baseString)
位于Xero.Api.Infrastructure.OAuth.Signing.RsaSha1Signer.CreateSignature(X509Certificate2证书、IToken令牌、Uri Uri、字符串动词、字符串验证器、布尔更新令牌、字符串回调)
在Xero.Api.Example.Applications.Private.PrivateAuthenticator.GetSignature(IConsumer使用者、IUser用户、Uri用户、字符串动词、IConsumer使用者1)
位于Xero.Api.Infrastructure.Http.HttpClient.CreateRequest(字符串端点、字符串方法、字符串接受、字符串查询)
位于Xero.Api.Infrastructure.Http.HttpClient.Get(字符串端点,字符串查询)
位于Xero.Api.Infrastructure.Http.XeroHttpClient.Get[TResult,treresponse](字符串端点)
位于Xero.Api.Common.xeroredpoint`3.Get(字符串端点,字符串子级)
在Xero.Api.Common.XeroReadEndpoint`3.Find处(字符串子项)
位于Xero.Api.Common.xeroredpoint`3.Find(Guid子级)
在Register.Invoicing.b\u create\u invoicines\u单击C:\SVN\Circles\RegistrationSystem\Register\Register\Invoicing.aspx.cs:第203行中的(对象发送方,事件参数e)
在System.Web.UI.WebControls.Button.OnClick(EventArgs e)中
位于System.Web.UI.WebControl.Button.RaisePostBackEvent(String eventArgument)
在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
当我在应用程序池中将“启用32位应用程序”设置为true时,错误消失了。我发现很困惑为什么设置为false时它可以工作,但作为具有管理权限的用户运行应用程序池
我希望对发生的事情有一个更好的解释。是的,这给我带来了一些问题,因为我有一个Azure功能,因此无法正常工作,非常令人沮丧,也许它确实需要管理访问权限?@robbiefan我不这么认为-正如我所说的,当启用32位时,它可以正常工作,而不需要管理员身份。。。。