2015-04-23 35 views
0

在使用RSACryptoServiceProvider的RSA加密中使用ASP.NET C# ,我得到此錯誤爲什麼? 什麼是我的代碼錯誤?沒有足夠的存儲空間可用於處理此命令在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: Not enough storage is available to process this command. at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey) at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP) at DataEncryptDecrypt.Encryption.newDcrypt(String text) in e:\VS Projects\DataEncryptDecrypt\DataEncryptDecrypt\Encryption.asmx.cs:line 180

+1

請提供您遇到的錯誤 –

+0

請提供異常堆棧跟蹤 –

+0

請刪除此異常。我正在努力解決,但它仍然。我在谷歌搜索,但沒有有用的解決方案找到。 –

回答

1

我有同樣的問題,並解決它如下:

要麼你嘗試錯誤的關鍵;或者密鑰不存在於csp密鑰庫中。

相關問題