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.
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
public class PrivateKey : object
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()
PrivateKey(Byte[])
Creates a PrivateKey instance from the given
privateKey
),
which encodes a valid
ECDSA private key.
Declaration
public PrivateKey(byte[] privateKey)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | privateKey | A valid |
Remarks
A valid
See Also
Properties
| Improve this Doc View SourceByteArray
A
Declaration
public byte[] ByteArray { get; }
Property Value
Type | Description |
---|---|
Byte[] |
Remarks
An encoded
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
| Improve this Doc View SourcePublicKey
The corresponding PublicKey of this private key.
Declaration
public PublicKey PublicKey { get; }
Property Value
Type | Description |
---|---|
PublicKey |
Methods
| Improve this Doc View SourceDecrypt(Byte[])
Converts a ciphertext
which was encrypted with
the corresponding PublicKey to the plain message.
Declaration
public byte[] Decrypt(byte[] ciphertext)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | ciphertext | The encrypted data. |
Returns
Type | Description |
---|---|
Byte[] | The plain data the |
Remarks
Although the parameter name ciphertext
has the
word “text”, both a ciphertext
and a returned message are a
Exceptions
Type | Condition |
---|---|
InvalidCiphertextException | Thrown when the given
|
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. |
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 |
Returns
Type | Description |
---|---|
Byte[] | A signature that verifies the |
See Also
Operators
| Improve this Doc View SourceEquality(PrivateKey, PrivateKey)
Declaration
public static bool operator ==(PrivateKey left, PrivateKey right)
Parameters
Type | Name | Description |
---|---|---|
PrivateKey | left | |
PrivateKey | right |
Returns
Type | Description |
---|---|
Boolean |
Inequality(PrivateKey, PrivateKey)
Declaration
public static bool operator !=(PrivateKey left, PrivateKey right)
Parameters
Type | Name | Description |
---|---|---|
PrivateKey | left | |
PrivateKey | right |
Returns
Type | Description |
---|---|
Boolean |