|
//------------------------------------------------------------------------
// (c) 2002-2004 by Per Anderson. All rights reserved.
//------------------------------------------------------------------------
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Reflection;
using System.Security.Cryptography;
using System.Collections;
using System.ComponentModel;
namespace Bullfrog.Compress.RSA
{
public class Validator : RSA1024Util
{
public Validator() : base()
{
}
public Validator(string xmlkey) : base(xmlkey)
{
}
public Validator(byte[] snkbuf) : base(snkbuf)
{
}
protected RSAPKCS1SignatureDeformatter _defmt = null;
protected RSAPKCS1SignatureDeformatter Defmt
{
get
{
if (_defmt == null)
{
_defmt = new RSAPKCS1SignatureDeformatter(RSA);
_defmt.SetHashAlgorithm("SHA1");
}
return _defmt;
}
}
public virtual void SetKey(AsymmetricAlgorithm key)
{
Defmt.SetKey(key);
}
public bool VerifySignature(string str_orig, byte[] signed)
{
if (_rsa == null)
return false;
byte[] orig = PlainTextToByte(str_orig);
return VerifySignature(orig, signed);
}
public bool VerifySignature(string str_orig, string str_signed)
{
if (_rsa == null)
return false;
byte[] orig = PlainTextToByte(str_orig);
byte[] signed = Base64StringToByte(str_signed);
return VerifySignature(orig, signed);
}
public bool VerifySignature(byte[] orig, byte[] signed)
{
if (_rsa == null)
return false;
if ((orig == null) || (orig.Length < 1)) return false;
if ((signed == null) || (signed.Length < 1)) return false;
byte[] hash = SHA.ComputeHash(orig, 0, orig.Length);
return Defmt.VerifySignature(hash, signed);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Per Anderson is the founder of Sunfrog Technologies LLC, http://sunfrog-tech.com .