[英]Not enough storage is available to process this command In RSA Encryption
在使用ASP.NET C#使用RSACryptoServiceProvider进行RSA加密时,为什么会出现此错误? 我的代码有什么错误?
[WebMethod]
public string newDcrypt(string text)
{
UnicodeEncoding encoder = new UnicodeEncoding();
string publickey = HttpContext.Current.Server.MapPath("Keys/publickey.pem");
string privatekey = HttpContext.Current.Server.MapPath("Keys/privatekey.pem");
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
privatekey = RSA.ToXmlString(true);
byte[] datatodecrypt = Convert.FromBase64String(text);
RSA.FromXmlString(privatekey);
byte[] decryptdata = RSA.Decrypt(datatodecrypt, false);
return Encoding.UTF8.GetString(decryptdata);
}
在这行代码上的错误。
var decryptdata = RSA.Decrypt(datatodecrypt, false)
加密很好,这里是加密代码。
[WebMethod]
public string NewEncrypt(string text)
{
UnicodeEncoding encoder = new UnicodeEncoding();
string publickey = HttpContext.Current.Server.MapPath("Keys/publickey.pem");
string privatekey = HttpContext.Current.Server.MapPath("Keys/privatekey.pem");
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
publickey = RSA.ToXmlString(true);
var datatoencrypt = encoder.GetBytes(text);
var encryptedbytearray = RSA.Encrypt(datatoencrypt, false);
RSA.FromXmlString(publickey);
return Convert.ToBase64String(encryptedbytearray);
}
错误:
System.Security.Cryptography.CryptographicException: 没有足够的存储空间来处理此命令。 在System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)处.decrypt(Byte [] rgb,布尔型fOAEP)位于e:\\ VS Projects \\ DataEncryptDecrypt \\ DataEncryptDecrypt \\ Encryption.asmx.cs:line 180中的DataEncryptDecrypt.Encryption.newDcrypt(String text)
我遇到了相同的问题,并按以下步骤解决了它:
您正在尝试输入错误的密钥; 或者该密钥在csp密钥库中不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.