Show / Hide Table of Contents

Class PrivateKey

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Inheritance
Object
PrivateKey
Implements
IEquatable<PrivateKey>
Inherited Members
Object.Equals(Object, Object)
System.Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
System.Object.ToString()
Namespace: Libplanet.Crypto
Assembly: Libplanet.Crypto.dll
Syntax
public class PrivateKey : IEquatable<PrivateKey>
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

Constructors

| Improve this Doc View Source

PrivateKey()

Generates a new unique PrivateKey instance. It can be analogous to creating a new account in a degree.

Declaration
public PrivateKey()
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

PrivateKey(Byte[], Boolean)

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Declaration
public PrivateKey(byte[] unverifiedKey, bool informedConsent)
Parameters
Type Name Description
System.Byte[] unverifiedKey
System.Boolean informedConsent
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

PrivateKey(IReadOnlyList<Byte>)

Creates a PrivateKey instance from the given System.Bytes (i.e., privateKey), which encodes a valid ECDSA private key.

Declaration
public PrivateKey(IReadOnlyList<byte> privateKey)
Parameters
Type Name Description
IReadOnlyList<System.Byte> privateKey

A valid System.Bytes that encodes an ECDSA private key.

Remarks

A valid System.Byte array for a PrivateKey can be encoded using ByteArray property.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the given privateKey is too short or too long.

See Also
ByteArray
| Improve this Doc View Source

PrivateKey(String)

Creates a PrivateKey instance from the given hexadecimal String (i.e.,hex).

Declaration
public PrivateKey(string hex)
Parameters
Type Name Description
String hex

A hexadecimal string of a private key's ByteArray.

Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

Exceptions
Type Condition
System.ArgumentNullException

Thrown when the given hex string is null.

ArgumentOutOfRangeException

Thrown when the length of the given hex string is too short or too long.

FormatException

Thrown when the given hex string is not a valid hexadecimal string.

See Also
PublicKey

Properties

| Improve this Doc View Source

Address

The corresponding Address derived from a PrivateKey. This is the same as the one derived from PublicKey.

Declaration
public Address Address { get; }
Property Value
Type Description
Address
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

ByteArray

An encoded System.Byte array representation.

Declaration
[Pure]
public ImmutableArray<byte> ByteArray { get; }
Property Value
Type Description
System.Collections.Immutable.ImmutableArray<System.Byte>
Remarks

An encoded System.Byte array representation can be recovered to a PrivateKey instance again using PrivateKey(IReadOnlyList<Byte>) constructor.

As like PrivateKey instances, it also must be kept secret. In practice, this must not be sent over the network, and be securely stored in the file system. If you just want to store the in-memory private key in the persistent storage, use or .

To get a mutable array instead of immutable one, use ToByteArray() method instead.

See Also
ToByteArray()
PrivateKey(IReadOnlyList<Byte>)
| Improve this Doc View Source

PublicKey

The corresponding PublicKey of this private key.

Declaration
public PublicKey PublicKey { get; }
Property Value
Type Description
PublicKey
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey

Methods

| Improve this Doc View Source

Decrypt(Byte[])

Decrypts a ciphertext which was encrypted with the corresponding PublicKey to the original plain text.

Declaration
[Pure]
public byte[] Decrypt(byte[] ciphertext)
Parameters
Type Name Description
System.Byte[] ciphertext

The encrypted message.

Returns
Type Description
System.Byte[]

The decrypted original message.

Remarks

Although the parameter name ciphertext has the word “text”, both a ciphertext and a returned message are System.Bytes, not Unicode Strings.

Exceptions
Type Condition
InvalidCiphertextException

Thrown when the given ciphertext is invalid.

See Also
Encrypt(Byte[])
| Improve this Doc View Source

Decrypt(ImmutableArray<Byte>)

Decrypts a ciphertext which was encrypted with the corresponding PublicKey to the original plain text.

Declaration
[Pure]
public ImmutableArray<byte> Decrypt(ImmutableArray<byte> ciphertext)
Parameters
Type Name Description
System.Collections.Immutable.ImmutableArray<System.Byte> ciphertext

The encrypted message.

Returns
Type Description
System.Collections.Immutable.ImmutableArray<System.Byte>

The decrypted original message.

Remarks

Although the parameter name ciphertext has the word “text”, both a ciphertext and a returned message are System.Bytes, not Unicode Strings.

Exceptions
Type Condition
InvalidCiphertextException

Thrown when the given ciphertext is invalid.

See Also
Encrypt(ImmutableArray<Byte>)
| Improve this Doc View Source

Equals(PrivateKey)

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Declaration
public bool Equals(PrivateKey other)
Parameters
Type Name Description
PrivateKey other
Returns
Type Description
System.Boolean
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

Equals(Object)

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
System.Boolean
Overrides
Object.Equals(Object)
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

ExchangeKey(PublicKey)

Securely exchange a SymmetricKey with a peer's PublicKey. Two parties can agree on a (new, unique, and typically temporal) key without revealing to any eavesdropping party what key has been agreed upon.

Technically it is ECDH, a Diffie–Hellman key exchange of elliptic-curve version.

Declaration
[Pure]
public SymmetricKey ExchangeKey(PublicKey publicKey)
Parameters
Type Name Description
PublicKey publicKey

The PublicKey possessed by a peer to whom exchange a private key with.

Returns
Type Description
SymmetricKey

An exchanged (agreed) SymmetricKey. Note that it is not an elliptic-curve private key, but an AES key.

Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

FromString(String)

Creates a PrivateKey instance from hexadecimal string of bytes.

Declaration
[Pure]
public static PrivateKey FromString(string hex)
Parameters
Type Name Description
String hex

A hexadecimal string of a private key's ByteArray.

Returns
Type Description
PrivateKey

A created PrivateKey instance.

Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

Exceptions
Type Condition
System.ArgumentNullException

Thrown when the given hex string is null.

ArgumentOutOfRangeException

Thrown when the length of the given hex string is too short or too long.

FormatException

Thrown when the given hex string is not a valid hexadecimal string.

See Also
PublicKey
| Improve this Doc View Source

GetHashCode()

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32
Overrides
Object.GetHashCode()
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

Sign(Byte[])

Creates a signature from the given message.

A created signature can be verified by the corresponding PublicKey.

Signatures can be created by only the PrivateKey which corresponds a PublicKey to verify these signatures.

To sum up, a signature is used to guarantee:

  • that the message was created by someone possessing the corresponding PrivateKey,
  • that the possessor cannot deny having sent the message, and
  • that the message was not forged in the middle of transit.
Declaration
public byte[] Sign(byte[] message)
Parameters
Type Name Description
System.Byte[] message

A message System.Bytes to sign.

Returns
Type Description
System.Byte[]

A signature that proves the authenticity of the message. It can be verified using Verify(IReadOnlyList<Byte>, IReadOnlyList<Byte>) method.

Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
Verify(IReadOnlyList<Byte>, IReadOnlyList<Byte>)
| Improve this Doc View Source

Sign(ImmutableArray<Byte>)

Creates a signature from the given message.

A created signature can be verified by the corresponding PublicKey.

Signatures can be created by only the PrivateKey which corresponds a PublicKey to verify these signatures.

To sum up, a signature is used to guarantee:

  • that the message was created by someone possessing the corresponding PrivateKey,
  • that the possessor cannot deny having sent the message, and
  • that the message was not forged in the middle of transit.
Declaration
public ImmutableArray<byte> Sign(ImmutableArray<byte> message)
Parameters
Type Name Description
System.Collections.Immutable.ImmutableArray<System.Byte> message

A message System.Bytes to sign.

Returns
Type Description
System.Collections.Immutable.ImmutableArray<System.Byte>

A signature that proves the authenticity of the message. It can be verified using Verify(IReadOnlyList<Byte>, IReadOnlyList<Byte>) method.

Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
Verify(IReadOnlyList<Byte>, IReadOnlyList<Byte>)
| Improve this Doc View Source

ToByteArray()

Encodes the private key into a corresponding mutable System.Byte array representation.

Declaration
[Pure]
public byte[] ToByteArray()
Returns
Type Description
System.Byte[]

An encoded System.Byte array representation. It guarantees that returned arrays are never reused, and mutating on them does not affect PrivateKey instance's internal states.

Remarks

An encoded System.Byte array representation can be recovered to a PrivateKey instance again using PrivateKey(IReadOnlyList<Byte>) constructor.

As like PrivateKey instances, it also must be kept secret. In practice, this must not be sent over the network, and be securely stored in the file system. If you just want to store the in-memory private key in the persistent storage, use or .

To get an immutable array instead of mutable one, use ByteArray property.

See Also
ByteArray
PrivateKey(IReadOnlyList<Byte>)

Operators

| Improve this Doc View Source

Equality(PrivateKey, PrivateKey)

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Declaration
public static bool operator ==(PrivateKey left, PrivateKey right)
Parameters
Type Name Description
PrivateKey left
PrivateKey right
Returns
Type Description
System.Boolean
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey
| Improve this Doc View Source

Inequality(PrivateKey, PrivateKey)

A secret part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to create signatures, which can be verified with the corresponding PublicKey, as well as to decrypt messages which were encrypted with the corresponding PublicKey.

Note that it uses secp256k1 as the parameters of the elliptic curve, which is the same to Bitcoin and Ethereum. It means private keys generated for Bitcoin/Ethereum can be used by Libplanet-backed games/apps too.

Declaration
public static bool operator !=(PrivateKey left, PrivateKey right)
Parameters
Type Name Description
PrivateKey left
PrivateKey right
Returns
Type Description
System.Boolean
Remarks

These (and any derived representations, e.g., ByteArray) must be kept secret, if they are exposed, an attacker will be able to forge signatures.

Every PrivateKey object is immutable.

See Also
PublicKey

Implements

System.IEquatable<T>

See Also

PublicKey
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium