这里我必须总结一下,因为RSACryptoServiceProvider 引发的异常快使我疯掉了!
代码:
WindowsIdentity wi = Logon(UserName, Password);if (null != wi) { WindowsImpersonationContext wic = wi.Impersonate(); CspParameters cp = new CspParameters(); cp.ProviderType = 1; cp.Flags = CspProviderFlags.UseMachineKeyStore; cp.KeyNumber = (int)KeyNumber.Exchange; cp.KeyContainerName = "KEY_1"; RSACryptoServiceProvider csp = new RSACryptoServiceProvider( cp); this.txtPublicKey.Text = this.PublicKey = csp.ToXmlString(false); csp.Clear(); wic.Undo();
我最先遇到:
System.Security.Cryptography.CryptographicException,发生位置是aspnet_wp.exe(1128)----------->windows XP
System.Security.Cryptography.CryptographicException,发生位置是w3wp.exe------------------>windows Server 2003
症状:是我用了加密算法后,把应用挂在IIS上,就时不时报如上错。
解决:
while impersonated and dont clean up the keys of the RSACryptoProvider using the clear method while impersonated.
解决步骤:
Impersonateuser
Create a new RSACryptoServiceProvider (pair)
Encrypt or Decrypt your data
Call clear to release the keys (pair.Clear())
Undo impersonation
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索加密
, csp
, security
, cp
, 加密 csp
, The
疯掉了
rsa加密算法、rsa加密、rsa在线加密解密、java rsa加密、c rsa加密,以便于您获取更多的相关知识。