• Design
  • API Reference
  • Changelog
  • Contribute
Show / Hide Table of Contents
  • Libplanet
    • Address
    • AddressExtension
    • ByteUtil
    • Hashcash
    • Hashcash.Stamp
    • HashDigest<T>
    • HashDigestExtension
    • Nonce
  • Libplanet.Action
    • AccountStateGetter
    • ActionEvaluation<T>
    • ActionTypeAttribute
    • AddressStateMap
    • IAccountStateDelta
    • IAction
    • IActionContext
    • IRandom
    • MissingActionTypeException
    • PolymorphicAction<T>
  • Libplanet.Blockchain
    • BlockChain<T>
  • Libplanet.Blockchain.Policies
    • BlockPolicy<T>
    • BlockPolicyExtension
    • IBlockPolicy<T>
  • Libplanet.Blocks
    • Block<T>
    • InvalidBlockDifficultyException
    • InvalidBlockException
    • InvalidBlockHashException
    • InvalidBlockIndexException
    • InvalidBlockNonceException
    • InvalidBlockPreviousHashException
    • InvalidBlockTimestampException
  • Libplanet.Crypto
    • InvalidCiphertextException
    • PrivateKey
    • PublicKey
    • SymmetricKey
  • Libplanet.Net
    • BlockDownloadState
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PeerSetDelta
    • Swarm
    • SwarmException
  • Libplanet.Serialization
    • BencodexFormatter<T>
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • FileStore
    • IStore
    • NamespaceNotFoundException
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId
    • UnexpectedlyTerminatedTxRehearsalException

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
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
[Equals]
public class 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()
| Improve this Doc View Source

PrivateKey(Byte[])

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

Declaration
public PrivateKey(byte[] privateKey)
Parameters
Type Name Description
Byte[] privateKey

A valid Byte array that encodes an ECDSA private key.

Remarks

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

See Also
ByteArray

Properties

| Improve this Doc View Source

ByteArray

A Byte array encoding of this private key.

Declaration
[Pure]
public byte[] ByteArray { get; }
Property Value
Type Description
Byte[]
Remarks

An encoded Byte array representation can recover a PrivateKey object again using its constructor (i.e., PrivateKey(Byte[]).

As like PrivateKey instances, this also must be kept secret. In practice, this must not be sent over the network, and be securely stored in the file system. For the most part, modern operating systems, mobile ones in particular, provide their own API to store password and private keys in the secure manner, which means they encrypt things to store using their own hardware security unit if possible. See also Android keystore system or iOS Secure Enclave.

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

PublicKey

The corresponding PublicKey of this private key.

Declaration
[Pure]
[IgnoreDuringEquals]
public PublicKey PublicKey { get; }
Property Value
Type Description
PublicKey

Methods

| Improve this Doc View Source

Decrypt(Byte[])

Converts a ciphertext which was encrypted with the corresponding PublicKey to the plain message.

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

The encrypted data.

Returns
Type Description
Byte[]

The plain data the ciphertext encrypted.

Remarks

Although the parameter name ciphertext has the word “text”, both a ciphertext and a returned message are a Byte string, not a Unicode String.

Exceptions
Type Condition
InvalidCiphertextException

Thrown when the given ciphertext is invalid.

See Also
Encrypt(Byte[])
| 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.

| 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
Byte[] message

A message to sign in Byte array representation.

Returns
Type Description
Byte[]

A signature that verifies the message. It can be verified using Verify(Byte[], Byte[]) method.

See Also
Verify(Byte[], Byte[])

See Also

PublicKey
  • Improve this Doc
  • View Source
Back to top Copyright © 2019 Planetarium
Generated by DocFX