使用RSA算法加密文件 [英] Encrypt a file using RSA Algorythm
问题描述
您好专家,
我在C#.net中制作了一个小型桌面应用程序.我的要求是我想使用RSA算法加密文本文件.我已经使用CAPICOMM.dll完成了该加密,但是现在我想使用RSA算法来完成加密,在该算法中,我将使用公钥加密文件,并使用私钥解密加密的文件.
以下是我实现的代码,但给了我一个错误!:confused:
Hello Experts,
I made one small desktop application in C#.net. My requirement is i want to encrypt a text file using RSA Algorithm. I already done this encyption using CAPICOMM.dll, but now I want to do it using RSA Algorithm in which I will use Public key to encrypt the file and Private key to decrypt the encrypted file.
Below is my code that I implemented but it gives me an error!!:confused:
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes("Hello there");
byte[] encryptedData;
byte[] decryptedData;
//Create a new instance of RSACryptoServiceProvider to generate
//public and private key data.
//CspParameters param = new CspParameters(
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
//Pass the data to ENCRYPT, the public key information
RSA.FromXmlString(SelectedCertificate.PublicKey.Key.ToXmlString(false));
encryptedData = RSA.Encrypt(dataToEncrypt, false);
//Pass the data to DECRYPT, the private key information
RSA.FromXmlString(SelectedCertificate.PrivateKey.ToXmlString(false));
decryptedData = RSA.Decrypt(encryptedData, false);
//Display the decrypted plaintext
}
需要您的建议.提前谢谢...
[edit]标记,次要拼写-OriginalGriff [/edit]
Need your suggestion. Thanks in advance...
[edit]Tags, minor spelling - OriginalGriff[/edit]
推荐答案
嘿..
我认为您可以找到,理解并使用此处
的方法 希望这对您有帮助...; P
Hey..
I think you can find ,understand and use the method that is Here
Hope this helps... ;P
这篇关于使用RSA算法加密文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!