Show / Hide Table of Contents

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
Implements
IEquatable<PublicKey>
Inherited Members
Object.Equals(Object, Object)
System.Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: Libplanet.Crypto
Assembly: Libplanet.Crypto.dll
Syntax
[TypeConverter(typeof(PublicKeyTypeConverter))]
[JsonConverter(typeof(PublicKeyJsonConverter))]
public class PublicKey : IEquatable<PublicKey>
Remarks

Every PublicKey object is immutable.

Constructors

| Improve this Doc View Source

PublicKey(IReadOnlyList<Byte>)

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

Declaration
public PublicKey(IReadOnlyList<byte> publicKey)
Parameters
Type Name Description
IReadOnlyList<System.Byte> publicKey

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

Remarks

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

See Also
Format(Boolean)

Properties

| Improve this Doc View Source

Address

The corresponding Address derived from a PublicKey.

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

Every PublicKey object is immutable.

See Also
PrivateKey
Address

Methods

| Improve this Doc View Source

Encrypt(Byte[])

Encrypts a plaintext message to a ciphertext, which can be decrypted with the corresponding PrivateKey.

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

A binary data to encrypt.

Returns
Type Description
System.Byte[]

A ciphertext that was encrypted from the original message. This can be decrypted with the corresponding PrivateKey.

Remarks

Although the word “ciphertext” has the word “text”, a returned ciphertext is not a Unicode String, but a mutable System.Byte array.

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

Encrypt(ImmutableArray<Byte>)

Encrypts a plaintext message to a ciphertext, which can be decrypted with the corresponding PrivateKey.

Declaration
public ImmutableArray<byte> Encrypt(ImmutableArray<byte> message)
Parameters
Type Name Description
System.Collections.Immutable.ImmutableArray<System.Byte> message

A binary data to encrypt.

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

A ciphertext that was encrypted from the original message. This can be decrypted with the corresponding PrivateKey.

Remarks

Although the word “ciphertext” has the word “text”, a returned ciphertext is not a Unicode String, but a mutable System.Byte array.

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

Equals(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.

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

Every PublicKey object is immutable.

See Also
PrivateKey
Address
| Improve this Doc View Source

Equals(Object)

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.

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

Every PublicKey object is immutable.

See Also
PrivateKey
Address
| Improve this Doc View Source

Format(Boolean)

Encodes this public key into a mutable System.Byte array representation.

To get an immutable one, use ToImmutableArray(Boolean) method instead.

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

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

Returns
Type Description
System.Byte[]

An encoded mutable System.Byte array representation. It can be recovered to a PublicKey instance again using PublicKey(IReadOnlyList<Byte>) constructor whether it is compressed or not.

Remarks

Every PublicKey object is immutable.

See Also
ToImmutableArray(Boolean)
PublicKey(IReadOnlyList<Byte>)
| Improve this Doc View Source

FromHex(String)

Creates a PublicKey instance from its hexadecimal representation.

Declaration
public static PublicKey FromHex(string hex)
Parameters
Type Name Description
String hex

The hexadecimal representation of the public key to load. Case insensitive, and accepts either compressed or uncompressed.

Returns
Type Description
PublicKey

The parsed PublicKey.

Remarks

Every PublicKey object is immutable.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the length of the given hex string is an odd number.

FormatException

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

See Also
ToHex(Boolean)
| Improve this Doc View Source

GetHashCode()

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.

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

Every PublicKey object is immutable.

See Also
PrivateKey
Address
| Improve this Doc View Source

ToHex(Boolean)

Gets the public key's hexadecimal representation in compressed form.

Declaration
public string ToHex(bool compress)
Parameters
Type Name Description
System.Boolean compress

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

Returns
Type Description
String

The hexadecimal string of the public key's compressed bytes.

Remarks

Every PublicKey object is immutable.

See Also
FromHex(String)
| Improve this Doc View Source

ToImmutableArray(Boolean)

Encodes this public key into a immutable System.Byte array representation.

To get an mutable one, use Format(Boolean) method instead.

Declaration
[Pure]
public ImmutableArray<byte> ToImmutableArray(bool compress)
Parameters
Type Name Description
System.Boolean compress

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

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

An encoded immutable System.Byte array representation. It can be recovered to a PublicKey instance again using PublicKey(IReadOnlyList<Byte>) constructor whether it is compressed or not.

Remarks

Every PublicKey object is immutable.

See Also
Format(Boolean)
PublicKey(IReadOnlyList<Byte>)
| Improve this Doc View Source

ToString()

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.

Declaration
public override string ToString()
Returns
Type Description
String
Overrides
System.Object.ToString()
Remarks

Every PublicKey object is immutable.

See Also
PrivateKey
Address
| Improve this Doc View Source

Verify(IReadOnlyList<Byte>, IReadOnlyList<Byte>)

Verifies whether a signature proves authenticity of message with the corresponding PrivateKey.

Declaration
[Pure]
public bool Verify(IReadOnlyList<byte> message, IReadOnlyList<byte> signature)
Parameters
Type Name Description
IReadOnlyList<System.Byte> message

A original plaintext message that the signature tries to prove its authenticity. I.e., an argument data passed to Sign(Byte[]) or Sign(ImmutableArray<Byte>) methods.

IReadOnlyList<System.Byte> signature

A signature which tries to authenticity of message. I.e., a data that Sign(Byte[]) or Sign(ImmutableArray<Byte>) methods returned.

Returns
Type Description
System.Boolean

true if the signature proves authenticity of the message with the corresponding PrivateKey. Otherwise false.

Remarks

Every PublicKey object is immutable.

See Also
PrivateKey
Address

Operators

| Improve this Doc View Source

Equality(PublicKey, 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.

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

Every PublicKey object is immutable.

See Also
PrivateKey
Address
| Improve this Doc View Source

Inequality(PublicKey, 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.

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

Every PublicKey object is immutable.

See Also
PrivateKey
Address

Implements

System.IEquatable<T>

See Also

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