DSACryptoServiceProvider

ijas1981ijas1981 Member Posts: 19 ■□□□□□□□□□
this is where problem occurs

DSACryptoServiceProvider signer = new DSACryptoServiceProvider();



using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;


namespace ConsoleApplication1
{
class Program
{
static void Main(string[ args)
{

DSACryptoServiceProvider signer = new DSACryptoServiceProvider();

//step 2
FileStream file = new FileStream(args[0], FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(file);
byte[ data = reader.ReadBytes((int)file.Length);

//step 3
byte[ signature = signer.SignData(data);

//step 4
string publicKey = signer.ToXmlString(false);
Console.WriteLine(" siganture : " + Convert.ToBase64String(signature));
file.Close();

//verifying step 1
DSACryptoServiceProvider verifier= new DSACryptoServiceProvider();

//verifying step 2
verifier.FromXmlString(publicKey);

//verifying step 3
FileStream file2= new FileStream(args[0], FileMode.Open , FileAccess.Read);
BinaryReader reader2 = new BinaryReader(file2);
byte[ data2= reader2.ReadBytes((int)file2.Length);

//verifying step 4
if (verifier.VerifyData(data2, signature))
{
Console.WriteLine(" signature verfied ");
}
else
{
Console.WriteLine(" signature not verfied ");
}
reader2.Close();
file2.Close();

}
}
}

Comments

Sign In or Register to comment.