encrypt/decrypt file by RSACryptoServiceProvider
I need to encrypt/decrypt files (type pdf,txt,doc) by using RSA algorithm in c# I import keys from XMl file
I use this method
public byte[] DecryptData(byte[] encrypted)
{
int nBytes = encrypted.Length;
byte[] ByteArray = new byte[nBytes];
RSACryptoServiceProvider rsa=new RSACrypto开发者_如何转开发ServiceProvider();
StreamReader reader = new StreamReader(@"E:\test\keyStore\Receiver\PrivateKey.xml");
string PrivateKeyXML = reader.ReadToEnd();
rsa.FromXmlString(PrivateKeyXML);
reader.Close();
//store decrypt data
ByteArray = rsa.Decrypt(encrypted, false);
////convert bytes to string
//ss = Global.enc.GetString(fromEncrypt);
return ByteArray;
}
ERROR MESSAGE="The data to be decrypted exceeds the maximum for this modulus of 256 bytes."
please, help me
This is because RSACryptoServiceProvider (assymmetric) should be used only to encrypt the symmetric key used for encrypt a document.
精彩评论