ECDsaSignature

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

Creates and verifies digital signature using the Elliptic Curve Digital Signature Algorithm (ECDSA). This class cannot be inherited.

public sealed class ECDsaSignature : ISignatureProvider, ILicenseSerializable, ISignatureWriter, ISignatureKeyInfo

Inheritance

objectECDsaSignature

Implements

ISignatureProvider, ILicenseSerializable, ISignatureWriter, ISignatureKeyInfo

Inherited Members

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

Examples

// Sign data
ECDsaSignature signer = new ECDsaSignature();

// A private key is needed to sign data
signer.CreateKeyPair();

byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
byte[] signature = signer.SignData(data);

// To verify that the signature data we need only the public key
ECDsaSignature verifier = ECDsaSignature.FromKeys(signer.PublicKey);

// Returns true
bool result = verifier.VerifyData(data, signature);

Constructors

ECDsaSignature()

Create a new instance of class.

public ECDsaSignature()

Examples

// Sign data
ECDsaSignature signer = new ECDsaSignature();

// A private key is needed to sign data
signer.CreateKeyPair();

byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
byte[] signature = signer.SignData(data);

// To verify that the signature data we need only the public key
ECDsaSignature verifier = ECDsaSignature.FromKeys(signer.PublicKey);

// Returns true
bool result = verifier.VerifyData(data, signature);

ECDsaSignature(ECDsaKeySize)

Create a new instance of class with the given .

public ECDsaSignature(ECDsaKeySize keySize)

Parameters

NameDescription

keySize ECDsaKeySize

A value indicating the bit size of the key.

Examples

// Sign data using 256 bit key size
ECDsaSignature signer = new ECDsaSignature(ECDsaKeySize.KeySize256bit);

// A private key is needed to sign data
signer.CreateKeyPair();

byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
byte[] signature = signer.SignData(data);

// To verify that the signature data we need only the public key
ECDsaSignature verifier = ECDsaSignature.FromKeys(signer.PublicKey);

// Returns true
bool result = verifier.VerifyData(data, signature);

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

KeySize

Gets ECDSA algorithm key size.

public ECDsaKeySize KeySize { get; }

Property Value

ECDsaKeySize

PrivateKey

Gets the private key as an encoded Base32 string.

public string PrivateKey { get; }

Property Value

string

PublicKey

Gets the public key as an encoded Base32 string.

public string PublicKey { get; }

Property Value

string

Methods

CreateKeyPair()

Creates a new key pair.

public void CreateKeyPair()

See Also

ECDsaSignature

ExportKeys(bool)

Export ECDsa keys as base 64 encoded string.

public string ExportKeys(bool publicKeyOnly)

Parameters

NameDescription

publicKeyOnly bool

Whether to write only public key data.

Returns

NameDescription

The base 64 encoded ECDsa key.

FromKeys(string, string)

Creates an object from the given public and private keys.

public static ECDsaSignature FromKeys(string publicKey, string privateKey = null)

Parameters

NameDescription

publicKey string

The public key Base32 encoded string.

privateKey string

An optional private key Base32 encoded string.

Returns

NameDescription

The ECDsaSignature with the given keys.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

See Also

ECDsaSignature

ImportKeys(string)

Import ECDsa keys.

public void ImportKeys(string key)

Parameters

NameDescription

key string

The base64 encoded string ECDsa key.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when the requested operation is invalid.

SignData(byte[])

Generate the signature for the given data.

public byte[] SignData(byte[] data)

Parameters

NameDescription

data byte[]

The data to sign.

Returns

NameDescription

Returns the generated signature.

See Also

ECDsaSignature

VerifyData(byte[], byte[])

Verify data.

public bool VerifyData(byte[] data, byte[] signature)

Parameters

NameDescription

data byte[]

The data.

signature byte[]

The signature.

Returns

NameDescription

true if the signature is valid, false if is not valid.

See Also

ECDsaSignature

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.

See Also

RSASignature, XmlDigitalSignature

Last updated