• Overview
  • 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
    • ActionTypeAttribute
    • IAccountStateDelta
    • IAction
    • IActionContext
    • IRandom
    • MissingActionTypeException
    • PolymorphicAction<T>
    • RandomExtension
    • UnexpectedlyTerminatedActionException
  • Libplanet.Blockchain
    • BlockChain<T>
    • BlockChain<T>.TipChangedEventArgs
    • IncompleteBlockStatesException
    • MineBlockEventArgs<T>
  • Libplanet.Blockchain.Policies
    • BlockPolicy<T>
    • IBlockPolicy<T>
  • Libplanet.Blocks
    • Block<T>
    • InvalidBlockDifficultyException
    • InvalidBlockException
    • InvalidBlockHashException
    • InvalidBlockIndexException
    • InvalidBlockNonceException
    • InvalidBlockPreviousHashException
    • InvalidBlockTimestampException
    • InvalidGenesisBlockException
  • Libplanet.Crypto
    • CryptoConfig
    • DefaultCryptoBackend
    • ICryptoBackend
    • InvalidCiphertextException
    • PrivateKey
    • PublicKey
    • SymmetricKey
  • Libplanet.KeyStore
    • IncorrectPassphraseException
    • InvalidKeyJsonException
    • KeyJsonException
    • MismatchedAddressException
    • ProtectedPrivateKey
    • UnsupportedKeyJsonException
  • Libplanet.KeyStore.Ciphers
    • Aes128Ctr
    • ICipher
  • Libplanet.KeyStore.Kdfs
    • IKdf
    • Pbkdf2<T>
    • Scrypt
  • Libplanet.Net
    • ActionExecutionState
    • BlockDownloadState
    • BoundPeer
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PeerState
    • PreloadBlockDownloadFailEventArgs
    • PreloadState
    • StateDownloadState
    • Swarm<T>
    • SwarmException
  • Libplanet.Net.Protocols
    • PeerDiscoveryException
  • Libplanet.Serialization
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • ChainIdNotFoundException
    • DefaultStore
    • IStore
    • StoreExtension
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId

Class PublicKey

A public part of a key pair involved in ECDSA, the digital signature algorithm on which the Libplanet is based. It can be used to verify signatures created with the corresponding PrivateKey and to encrypt messages for someone possessing the corresponding PrivateKey. This can be distributed publicly, hence the name.

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

Inheritance
Object
PublicKey
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
public class PublicKey : object
Remarks

Every PublicKey object is immutable.

Constructors

| Improve this Doc View Source

PublicKey(Byte[])

Creates a PublicKey instance from the given array (i.e., publicKey), which encodes a valid ECDSA public key.

Declaration
public PublicKey(byte[] publicKey)
Parameters
Type Name Description
Byte[] publicKey

A valid array that encodes an ECDSA public key. It can be either compressed or not.

Remarks

A valid array for a PublicKey can be encoded using Format(Boolean) method.

See Also
Format(Boolean)

Methods

| Improve this Doc View Source

Encrypt(Byte[])

Converts a plain message to a ciphertext which can be decrypted with the corresponding PrivateKey.

Declaration
public byte[] Encrypt(byte[] message)
Parameters
Type Name Description
Byte[] message

A binary data to be encrypted.

Returns
Type Description
Byte[]

A ciphertext that was encrypted from the message and can be decrypted with the corresponding PrivateKey. (Although the word “ciphertext” has the word “text”, a returned ciphertext is not a Unicode , but a array.)

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

Format(Boolean)

Encodes this public key into a array representation.

Declaration
public byte[] Format(bool compress)
Parameters
Type Name Description
Boolean compress

Returns a short length representation if it is true. This option does not lose any information.

Returns
Type Description
Byte[]

An encoded array representation. It can recover a PublicKey object again using its constructor (i.e., PublicKey(Byte[])) regardless of compression.

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

Verify(Byte[], Byte[])

Verifies whether a signature was created from a message with the corresponding PrivateKey.

Declaration
public bool Verify(byte[] message, byte[] signature)
Parameters
Type Name Description
Byte[] message

A plain message that the signature was created from. That is, a data which was passed as an argument to Sign(Byte[]).

Byte[] signature

A signature that was created from the message. That is, a data which was returned by Sign(Byte[]).

Returns
Type Description
Boolean

true if the signature was created from the message with the corresponding PrivateKey. Otherwise false.

Extension Methods

AddressExtension.ToAddress(PublicKey)

See Also

PrivateKey
Address
  • Improve this Doc
  • View Source
Back to top Copyright © 2019–2020 Planetarium