XmlDigitalSignature

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

Provides a means to read and validate and digitally sign XML documents.

public class XmlDigitalSignature : ISignatureProvider, ISignatureWriter, IRSAKeys, ISignatureKeyInfo

Inheritance

objectXmlDigitalSignature

Implements

ISignatureProvider, ISignatureWriter, IRSAKeys, ISignatureKeyInfo

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

XmlDigitalSignature(RSA)

Initializes a new instance of the class with the specified RSA algorithm.

public XmlDigitalSignature(RSA rsa)

Parameters

NameDescription

rsa RSA

The RSA algorithm.

Exceptions

NameDescription

Thrown when the rsa argument is null.

XmlDigitalSignature(RSA, bool)

Initializes a new instance of the class with the specified RSA algorithm.

public XmlDigitalSignature(RSA rsa, bool generateKeyInfo)

Parameters

NameDescription

rsa RSA

The RSA algorithm.

generateKeyInfo bool

true to add public key information to signature element, false if not.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Fields

XmlDSigNamespace

The XML digital signature namespace.

public static readonly string XmlDSigNamespace

Field Value

string

Properties

AlgorithmName

Gets the name of the sign algorithm.

public string AlgorithmName { get; }

Property Value

string

GenerateKeyInfo

Gets or sets a value indicating whether the generate key information.

public bool GenerateKeyInfo { get; set; }

Property Value

bool

HasKeySize

Gets a value indicating whether this object has key size.

public bool HasKeySize { get; }

Property Value

bool

HasPrivateKey

Gets a value indicating whether this object has private key.

public bool HasPrivateKey { get; }

Property Value

bool

HasPublicKey

Gets a value indicating whether this object has public key.

public bool HasPublicKey { get; }

Property Value

bool

KeyPair

Gets or sets the RSA key pair.

public byte[] KeyPair { get; set; }

Property Value

byte[]

KeySize

Gets the key size.

public int KeySize { get; }

Property Value

int

RSA

Gets or sets the algorithm.

public RSA RSA { get; set; }

Property Value

RSA

SignatureValue

Gets the signature value.

public byte[] SignatureValue { get; }

Property Value

byte[]

Methods

CreateFromKeyContainer(string)

Creates an instance of from the specified key container.

public static XmlDigitalSignature CreateFromKeyContainer(string container)

Parameters

NameDescription

container string

The key container name.

Returns

NameDescription

The created object.

Exceptions

NameDescription

Thrown when the container argument is null.

CreateFromKeyFile(string, string)

Creates an instance of from the specified key pair file.

public static XmlDigitalSignature CreateFromKeyFile(string keyFile, string password = null)

Parameters

NameDescription

keyFile string

The key pair file path. This can be an SNK or PFX file.

password string

(Optional) the key password.

Returns

NameDescription

The created object.

Exceptions

NameDescription

Thrown when the keyFile argument is null.

CreateFromSignedXml(string)

Creates an object from the digitally signed XML document.

public static XmlDigitalSignature CreateFromSignedXml(string xml)

Parameters

NameDescription

xml string

The digitally signed XML document.

Returns

NameDescription

The created object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when the XML is not digitally signed.

LoadXml(string)

Loads an XML file to sign.

public void LoadXml(string xml)

Parameters

NameDescription

xml string

The XML document.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Sign()

Sign the XML.

public void Sign()

ToRSASignature()

Converts this object to an object.

public RSASignature ToRSASignature()

Returns

NameDescription

The object.

VerifySignature()

Verify the XML digital signature.

public bool VerifySignature()

Returns

NameDescription

true if the signature is valid, false if not.

WritePem(string, bool)

Writes the signature using PEM format to the specified file.

public void WritePem(string path, bool publicKeyOnly)

Parameters

NameDescription

path string

The file path.

publicKeyOnly bool

Whether to write only public key data.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

WritePem(Stream, bool)

Writes the signature using PEM format to the specified stream.

public void WritePem(Stream stream, bool publicKeyOnly)

Parameters

NameDescription

stream Stream

The stream to write.

publicKeyOnly bool

Whether to write only public key data.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

WriteXml(XmlWriter)

Writes the XML to the specified .

public void WriteXml(XmlWriter writer)

Parameters

NameDescription

writer XmlWriter

The XML writer.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

See Also

ECDsaSignature, RSASignature

Last updated