Show / Hide Table of Contents

Class ECDsaEncoding

Class with helper methods to encode and decode ECDSA signatures

Inheritance
Object
ECDsaEncoding
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: Lacuna.Pki.Asn1
Assembly: Lacuna.Pki.dll
Syntax
public static class ECDsaEncoding
Remarks

RFC 6979 -- Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA) -- does not specify an encoding for ECDSA signatures. Section 2.4 states:

The pair (r, s) is the signature. How a signature is to be encoded is not covered by the DSA and ECDSA standards themselves; a common way is to use a DER-encoded ASN.1 structure (a SEQUENCE of two INTEGERs, for r and s, in that order).

Therefore, each protocol is responsible for defining the encoding of ECDSA signatures.

This class contains methods for encoding and decoding ECDSA signatures between protocol-specific encodings from/to .NET's native representation of signatures.

Methods

DecodeX509Signature(Byte[], Int32)

Decodes an ECDSA signature encoded according to the X.509 standard into .NET's representation of an ECDSA signature

Declaration
public static byte[] DecodeX509Signature(byte[] berSignature, int qLength)
Parameters
Type Name Description
Byte[] berSignature

The X.509 encoded ECDSA signature

Int32 qLength

Length of the EC field, in bytes

Returns
Type Description
Byte[]

The ECDSA signature encoded in .NET's native encoding

Remarks

If you only have the length in bits of the key, use the method GetFieldLength to get the length in bytes of the field and pass it on the qLength parameter.

EncodeX509Signature(Byte[])

Encodes an ECDSA signature encoded in .NET's native encoding to X.509 encoding

Declaration
public static byte[] EncodeX509Signature(byte[] netSignature)
Parameters
Type Name Description
Byte[] netSignature

The ECDSA signature encoded in .NET's native encoding

Returns
Type Description
Byte[]

The ECDSA signature encoded in X.509 encoding

GetFieldLength(Int32)

Declaration
public static int GetFieldLength(int keyBitSize)
Parameters
Type Name Description
Int32 keyBitSize
Returns
Type Description
Int32

TryDecodeX509Signature(Byte[], Int32, out Byte[])

Decodes an ECDSA signature encoded according to the X.509 standard into .NET's representation of an ECDSA signature. A return value indicates whether the conversion succeeded.

Declaration
public static bool TryDecodeX509Signature(byte[] berSignature, int qLength, out byte[] netSignature)
Parameters
Type Name Description
Byte[] berSignature

The X.509 encoded ECDSA signature

Int32 qLength

Length of the EC field, in bytes

Byte[] netSignature

The ECDSA signature encoded in .NET's native encoding

Returns
Type Description
Boolean

true if berSignature was decoded successfully; otherwise, false.

Remarks

If you only have the length in bits of the key, use the method GetFieldLength to get the length in bytes of the field and pass it on the qLength parameter.

Back to top Copyright © 2015-2020 Lacuna Software