views:

25

answers:

0

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 RSACryptoServiceProvider();

    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