C# Class BitSharper.EcKey

Show file Open project: TangibleCryptography/BitSharper Class Usage Examples

Public Methods

Method Description
EcKey ( BigInteger privKey ) : System

Creates an ECKey given only the private key. This works because EC public keys are derivable from their private keys by doing a multiply with the generator value.

FromAsn1 ( byte asn1PrivKey ) : EcKey

Construct an ECKey from an ASN.1 encoded private key. These are produced by OpenSSL and stored by the BitCoin reference implementation in its wallet.

GetPrivKeyBytes ( ) : byte[]

Returns a 32 byte array containing the private key.

GetPrivateKeyEncoded ( NetworkParameters @params ) : DumpedPrivateKey

Exports the private key in the form used by the Satoshi client "dumpprivkey" and "importprivkey" commands. Use the DumpedPrivateKey.ToString method to get the string.

Sign ( byte input ) : byte[]

Calculates an ECDSA signature in DER format for the given input hash. Note that the input is expected to be 32 bytes long.

ToAddress ( NetworkParameters @params ) : Address

Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient).

ToAsn1 ( ) : byte[]

Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the BitCoin reference implementation in its wallet storage format.

ToString ( ) : string
Verify ( byte data, byte signature ) : bool

Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.

Verify ( byte data, byte signature, byte pub ) : bool

Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.

Private Methods

Method Description
EcKey ( ) : System
ExtractPrivateKeyFromAsn1 ( byte asn1PrivKey ) : BigInteger
PublicKeyFromPrivate ( BigInteger privKey ) : byte[]

Derive the public key by doing a point multiply of G * priv.

Method Details

EcKey() public method

Creates an ECKey given only the private key. This works because EC public keys are derivable from their private keys by doing a multiply with the generator value.
public EcKey ( BigInteger privKey ) : System
privKey Org.BouncyCastle.Math.BigInteger
return System

FromAsn1() public static method

Construct an ECKey from an ASN.1 encoded private key. These are produced by OpenSSL and stored by the BitCoin reference implementation in its wallet.
public static FromAsn1 ( byte asn1PrivKey ) : EcKey
asn1PrivKey byte
return EcKey

GetPrivKeyBytes() public method

Returns a 32 byte array containing the private key.
public GetPrivKeyBytes ( ) : byte[]
return byte[]

GetPrivateKeyEncoded() public method

Exports the private key in the form used by the Satoshi client "dumpprivkey" and "importprivkey" commands. Use the DumpedPrivateKey.ToString method to get the string.
public GetPrivateKeyEncoded ( NetworkParameters @params ) : DumpedPrivateKey
@params NetworkParameters
return DumpedPrivateKey

Sign() public method

Calculates an ECDSA signature in DER format for the given input hash. Note that the input is expected to be 32 bytes long.
public Sign ( byte input ) : byte[]
input byte
return byte[]

ToAddress() public method

Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient).
public ToAddress ( NetworkParameters @params ) : Address
@params NetworkParameters
return Address

ToAsn1() public method

Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the BitCoin reference implementation in its wallet storage format.
public ToAsn1 ( ) : byte[]
return byte[]

ToString() public method

public ToString ( ) : string
return string

Verify() public method

Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.
public Verify ( byte data, byte signature ) : bool
data byte Hash of the data to verify.
signature byte ASN.1 encoded signature.
return bool

Verify() public static method

Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.
public static Verify ( byte data, byte signature, byte pub ) : bool
data byte Hash of the data to verify.
signature byte ASN.1 encoded signature.
pub byte The public key bytes to use.
return bool