在WebService中使用RSA进行加密和解密操作时,出现的一种异常的
发布时间:2020-12-17 02:56:45 所属栏目:安全 来源:网络整理
导读:"CSP for this implementation could not be acquired" CryptographicException error during instantiation This article was previously published under Q322371 SYMPTOMS If you create an instance of the .NET RSACryptoServiceProvider class or DSAC
"CSP for this implementation could not be acquired" CryptographicException error during instantiation
This article was previously published under Q322371
SYMPTOMS
If you create an instance of the .NET
RSACryptoServiceProvider class or
DSACryptoServiceProvider class either directly or indirectly through the
SignedXml class,you may receive the following
CryptographicException class exception:
System.Security.Cryptography.CryptographicException:
You may receive this
CryptographicException error message when the .NET code is run in a Web service,a COM+ component,or an Active Server Pages (ASP) page.
CryptoAPI cryptographic service provider (CSP) for this implementation could not be acquired. at System.Security.Cryptography.RSACryptoServiceProvider ..ctor(Int32 dwKeySize,CspParameters parameters, Boolean useDefaultKeySize) at System.Security.Cryptography.RSACryptoServiceProvider ..ctor(CspParameters parameters) CAUSE
Underlying
base,enhanced,or
strong cryptographic service provider (CSP) implementations create a key container for storing an RSA public/private asymmetric key pair. Key containers are stored in user profiles. For performance reasons,the user profile is not loaded by the system under a scenario where the .NET code runs in a Web service,ASP page,or COM+. If the user profile is not loaded,a key container cannot be opened or created. Because a key container is required for
RSACryptoServiceProvider or
DSACryptoServiceProvider,the .NET code (when run from a Web Service,ASP Page,or COM+) fails by throwing the exception described in the "Symptoms" section of this article. If the same .NET code is run from the context of the interactive logged-on user,where the user profile is loaded by Winlogon,a key container
can be created and opened,and the code works under this scenario.
RESOLUTION
You have to instruct
RSACryptoServiceProvider or
DSACryptoServiceProvider to use
machine key store (as in the following sample code) in scenarios such as a Web service,or COM+,where the user profile is not loaded by the system for performance reasons. You can use the
CspParameters parameter in the
RSACryptoServiceProvider() constructor,as follows.
CspParameters CSPParam = new CspParameters(); CSPParam.Flags = CspProviderFlags.UseMachineKeyStore; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(CSPParam);The following C# sample code demonstrates how to use the machine key store when RSACryptoServiceProvider is used indirectly by the SignedXml class while signing an XML file or verifying a signed XML file. This sample code assumes that the XML file was signed by using RSA keys. The sample code signs an input XML file. The signed file is stored in EnvelopingSig.xml,which is then verified.
STATUS
This behavior is by design.
MORE INFORMATION
The exception described in the "Symptoms" section of this article also occurs if the application specifies the name of a
machine key store in
CspParameters,and the calling security context does not have the permissions to open it.
If the caller is running under the SYSTEM security context,CSP implementations automatically redirect to the machine key container. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angular2-routing – 如何在angular2中为router.url编写单元
- postgresql – 如何进入运行的postgres容器的psql?
- angular – 在’Observable’类型中不存在属性’unsubscrib
- 如何将角度2中的日期转换为’yyyy-MM-dd’格式
- angular1.3 video
- webservice 客户端不集成spring写法
- angularjs – 我应该使用id来定位元素吗?
- scala – 添加“extends AnyVal”会导致“类型参数不符合”
- WebService的两种方式SOAP和REST比较
- 访问WebService,因 URL 意外地以“/HelloWorld”结束,请求