简体   繁体   中英

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 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

这是因为RSACryptoServiceProvider(非对称)仅应用于加密用于加密文档的对称密钥。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM