C#中Rsa算法的源代码 [英] Source Code For Rsa Algorithm In C#
本文介绍了C#中Rsa算法的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以给我c#中的rsa算法的源代码,该代码通过code加密和解密文件.意味着使用StreamWriter函数.该函数将通过code给出文件并创建两个文件,一个被加密,另一个被解密文件.
Pls can anyone give me a source code for rsa algoritm in c# which encrypt & decrypt a file through code.means using StreamWriter function.that function which will give the file through code & create two files one is encrypted & other is decrypted file.
推荐答案
RSA加密,但仅用于字符串:
RSA encryption but just for strings:
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace RSA
{
class Program
{
static void Main(string[] args)
{
RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();//Encode String to Convert to Bytes
string data = "RsA EnCryPTion is cool!!!";//whatever you want to encrypt
Byte[] newdata = encoding.GetBytes(data);//convert to Bytes
Byte[] encrypted = myrsa.Encrypt(newdata, false);
Console.WriteLine("Encrypted Data: ");
for (int i = 0; i < encrypted.Length; i++)
{
Console.Write("{0} ", encrypted[i]);
}
Console.WriteLine();
Console.WriteLine();
Byte[] decrypted = myrsa.Decrypt(encrypted, false);//decrypt
Console.WriteLine("Decrypted Data: ");
string dData = encoding.GetString(decrypted); //encode bytes back to string
for (int i = 0; i < decrypted.Length; i++)
{
Console.Write("{0}", dData[i]);
}
}
}
}
这是一个普遍的要求,因此,互联网上有成千上万的文章/博客.
找到它们所需要做的就是想出一个合适的搜索词组并可以使用搜索引擎.
This is a common requirement and there are, therefore, thousands of articles/blogs on the internet.
All you have to do to find them is to think of a suitable search phrase and have access to a search engine.
这篇关于C#中Rsa算法的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文