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
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 SourcePrivateKey()
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
| Improve this Doc View SourcePrivateKey(IReadOnlyList<Byte>)
Creates a PrivateKey instance from the given privateKey
), which encodes a valid
ECDSA private key.
Declaration
public PrivateKey(IReadOnlyList<byte> privateKey)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<System.Byte> | privateKey | A valid |
Remarks
A valid
See Also
| Improve this Doc View SourcePrivateKey(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
| Improve this Doc View SourcePrivateKey(String)
Creates a PrivateKey instance from the given hexadecimal
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
Properties
| Improve this Doc View SourceAddress
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
| Improve this Doc View SourceByteArray
An encoded
Declaration
public ImmutableArray<byte> ByteArray { get; }
Property Value
Type | Description |
---|---|
ImmutableArray<System.Byte> |
Remarks
An encoded
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
To get a mutable array instead of immutable one, use ToByteArray() method instead.
See Also
| Improve this Doc View SourcePublicKey
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
Methods
| Improve this Doc View SourceDecrypt(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
Exceptions
Type | Condition |
---|---|
InvalidCiphertextException | Thrown when the given
|
See Also
| Improve this Doc View SourceDecrypt(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
Exceptions
Type | Condition |
---|---|
InvalidCiphertextException | Thrown when the given
|
See Also
| Improve this Doc View SourceEquals(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
| Improve this Doc View SourceEquals(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
| Improve this Doc View SourceExchangeKey(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
| Improve this Doc View SourceFromString(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
| Improve this Doc View SourceGetHashCode()
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
| Improve this Doc View SourceSign(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 |
Returns
Type | Description |
---|---|
ImmutableArray<System.Byte> | A signature that proves the authenticity of the |
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
| Improve this Doc View SourceSign(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 |
Returns
Type | Description |
---|---|
System.Byte[] | A signature that proves the authenticity of the |
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
| Improve this Doc View SourceToByteArray()
Encodes the private key into a corresponding mutable
Declaration
public byte[] ToByteArray()
Returns
Type | Description |
---|---|
System.Byte[] | An encoded |
Remarks
An encoded
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
To get an immutable array instead of mutable one, use ByteArray property.
See Also
Operators
| Improve this Doc View SourceEquality(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
| Improve this Doc View SourceInequality(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.