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
System.Object
PrivateKey
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(IReadOnlyList<Byte>)

Creates a PrivateKey instance from the given s (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 s that encodes an ECDSA private key.

Remarks

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

See Also
ByteArray
| 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(String)

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

Declaration
public PrivateKey(string hex)
Parameters
Type Name Description
System.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.

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 array representation.

Declaration
public ImmutableArray<byte> ByteArray { get; }
Property Value
Type Description
ImmutableArray<System.Byte>
Remarks

An encoded 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(ImmutableArray<Byte>)

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

Declaration
public ImmutableArray<byte> Decrypt(ImmutableArray<byte> ciphertext)
Parameters
Type Name Description
ImmutableArray<System.Byte> ciphertext

The encrypted message.

Returns
Type Description
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 s, not Unicode s.

Exceptions
Type Condition
InvalidCiphertextException

Thrown when the given ciphertext is invalid.

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

Decrypt(Byte[])

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

Declaration
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 s, not Unicode s.

Exceptions
Type Condition
InvalidCiphertextException

Thrown when the given ciphertext is invalid.

See Also
Encrypt(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(Nullable<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
System.Nullable<System.Object> obj
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

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
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
public static PrivateKey FromString(string hex)
Parameters
Type Name Description
System.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.

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
System.Int32
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(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
ImmutableArray<System.Byte> message

A message s to sign.

Returns
Type Description
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

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 s 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

ToByteArray()

Encodes the private key into a corresponding mutable array representation.

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

An encoded 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 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

See Also

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