一個發郵件的例子,涉及MSMQ,RSA,JMAIL
來源:互聯網
上載者:User
1.先產生公開金鑰密鑰
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
string publickey=crypt.ToXmlString(false);//(公開金鑰)
string privatekey=crypt.ToXmlString(true);
crypt.Clear();
StreamWriter one=new StreamWriter(@"c:a.txt",true,UTF8Encoding.UTF8);
one.Write(publickey);
StreamWriter two=new StreamWriter(@"c:.txt",true,UTF8Encoding.UTF8);
two.Write(privatekey);
one.Flush();
two.Flush();
one.Close();
two.Close();
Console.WriteLine("成功儲存公匙和密匙!");
2.對資訊加密,然後用通過隊列發送資訊
string from=TextBoxFrom.Text+DropDownList2.SelectedValue;
string sub=textBoxSub.Text;
string bodys=TextBoxBody.Text;
string pwd=TextBoxPwd.Text;
StreamReader sr = new StreamReader(@"c:a.txt",UTF8Encoding.UTF8);
string readpublickey = sr.ReadToEnd();
sr.Close();
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();