开发者

encrypt/decrypt file by RSACryptoServiceProvider

开发者 https://www.devze.com 2023-01-08 16:06 出处:网络
I need to encrypt/decrypt files (type pdf,txt,doc) by using RSA algorithm in c# I import keys from XMl file

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号