相关疑难解决方法(0)

如何使用RSA加密C#中的文件(大数据)

我是加密新手.我需要实现非对称加密算法,我认为它使用私钥/公钥.我开始使用RSACryptoServiceProvider的示例.加密的小数据是可以的.但是当在相对较大的数据"2行"上使用它时,我得到异常CryptographicException"Bad Length"!

//Create a new instance of RSACryptoServiceProvider.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{

    //Import the RSA Key information. This only needs
    //toinclude the public key information.
    //RSA.ImportParameters(RSAKeyInfo);
    byte[] keyValue = Convert.FromBase64String(publicKey);
    RSA.ImportCspBlob(keyValue);

    //Encrypt the passed byte array and specify OAEP padding.  
    //OAEP padding is only available on Microsoft Windows XP or
    //later.  
    encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
Run Code Online (Sandbox Code Playgroud)

然后我找到了一些使用CryptoStream加密大数据(或文件)的样本,并且只使用DES或3DES等对称算法,它们具有CreateEncryptor函数,将ICryptoTransform作为CryptoStream构造函数的输入之一返回!

CryptoStream cStream = new CryptoStream(fStream,
                new TripleDESCryptoServiceProvider().CreateEncryptor(Key, IV),
                CryptoStreamMode.Write);
Run Code Online (Sandbox Code Playgroud)

使用RSA加密文件的方法是什么?

c# 3des cryptography rsa encryption-asymmetric

41
推荐指数
5
解决办法
5万
查看次数

标签 统计

3des ×1

c# ×1

cryptography ×1

encryption-asymmetric ×1

rsa ×1