简体   繁体   English

通过RSACryptoServiceProvider加密/解密文件

[英]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 我需要在C#中使用RSA算法来加密/解密文件(类型为pdf,txt,doc),我从XMl文件导入密钥

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." “ ERROR MESSAGE =”要解密的数据超过此256字节模数的最大值。“

please, help me 请帮我

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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