using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.Text;
namespace Sign4
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Исходная строка
const string CLEAR_TEXT = "Объекты DSASignatureFormatter, " +
"DSASignatureDeformatter, RSAPKCS1SignatureFormatter, " +
"RSAPKCS1SignatureDeformatter";
// Инициализируем объекты
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();
DSASignatureFormatter DSAform = new DSASignatureFormatter(DSA);
DSASignatureDeformatter DSAdeform = new DSASignatureDeformatter(DSA);
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAPKCS1SignatureFormatter RSAform =
new RSAPKCS1SignatureFormatter(RSA);
RSAPKCS1SignatureDeformatter RSAdeform =
new RSAPKCS1SignatureDeformatter(RSA);
byte[] DSAhashText, DSAsignText, RSAhashText, RSAsignText;
UnicodeEncoding enc = new UnicodeEncoding();
// Хэшируем
DSAhashText = SHA1.ComputeHash(enc.GetBytes(CLEAR_TEXT));
RSAhashText = MD5.ComputeHash(enc.GetBytes(CLEAR_TEXT));
// Задаём имена хэш-алгоритмов
DSAform.SetHashAlgorithm("SHA1");
DSAdeform.SetHashAlgorithm("SHA1");
RSAform.SetHashAlgorithm("MD5");
RSAdeform.SetHashAlgorithm("MD5");
// Создаём подпись
DSAsignText = DSAform.CreateSignature(DSAhashText);
RSAsignText = RSAform.CreateSignature(RSAhashText);
Response.Write("<b>Clear text:</b> " + CLEAR_TEXT + "<br><br>");
// Осуществляем проверку и выводим результаты на экран
//DSA-------------
if (DSAdeform.VerifySignature(DSAhashText, DSAsignText) == true)
Response.Write("<b>DSA signature:</b> " +
enc.GetString(DSAsignText) +
" <font color='Green'>" +
"Good</font><br>");
else
Response.Write("<b>DSA signature:</b> " +
enc.GetString(DSAsignText) +
" <font color='Red'>" +
"Bad</font><br>");
//RSA-------------
if (RSAdeform.VerifySignature(RSAhashText, RSAsignText) == true)
Response.Write("<b>RSA signature:</b> " +
enc.GetString(RSAsignText) +
" <font color='Green'>" +
"Good</font>");
else
Response.Write("<b>RSA signature:</b> " +
enc.GetString(RSAsignText) +
" <font color='Red'>" +
"Bad</font>");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Алгоритм RSA
Кто поможет переобразовать этот исходник в С#?
Может я и не по теме - но алгоритм простой и реализовать его не сложно самому... почитай