|
//------------------------------------------------------------------------
// (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;
namespace Bullfrog.Compress.RSA
{
public class Signer : Validator
{
public Signer() : base()
{
}
public Signer(string xmlkey) : base(xmlkey)
{
}
public Signer(byte[] snkbuf) : base(snkbuf)
{
}
protected RSAPKCS1SignatureFormatter _fmt = null;
protected RSAPKCS1SignatureFormatter Fmt
{
get
{
if (_fmt == null)
{
_fmt = new RSAPKCS1SignatureFormatter(RSA);
_fmt.SetHashAlgorithm("SHA1");
}
return _fmt;
}
}
public override void SetKey(AsymmetricAlgorithm key)
{
base.SetKey(key);
Fmt.SetKey(key);
}
public byte[] SignToBytes(string str_orig)
{
byte[] orig = PlainTextToByte(str_orig);
return SignToBytes(orig);
}
public byte[] SignToBytes(byte[] orig)
{
if (_rsa == null) return null;
if ((orig == null) || (orig.Length < 1))
return null;
byte[] hash = SHA.ComputeHash(orig, 0, orig.Length);
return Fmt.CreateSignature(hash);
}
public string SignToString(string str_orig)
{
byte[] orig = PlainTextToByte(str_orig);
return SignToString(orig);
}
public string SignToString(byte[] orig)
{
byte[] signed = SignToBytes(orig);
string ret = ByteToBase64String(signed);
return ret;
}
}
}
|
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 .