Class ProtectedPrivateKey
Protects a PrivateKey with a passphrase (i.e., password).
Namespace: Libplanet.KeyStore
Assembly: Libplanet.dll
Syntax
public sealed class ProtectedPrivateKey : object
Constructors
| Improve this Doc View SourceProtectedPrivateKey(Address, IKdf, ImmutableArray<Byte>, ICipher, ImmutableArray<Byte>)
Loads a protected private key.
Declaration
public ProtectedPrivateKey(Address address, IKdf kdf, ImmutableArray<byte> mac, ICipher cipher, ImmutableArray<byte> ciphertext)
Parameters
Type | Name | Description |
---|---|---|
Address | address | The address of the protected private key. |
IKdf | kdf | A key derivation function to derive a symmetric key to decrypt a PrivateKey. |
ImmutableArray<Byte> | mac | MAC digest to check if a derived key is correct or not. |
ICipher | cipher | A symmetric cipher to decrypt a PrivateKey. |
ImmutableArray<Byte> | ciphertext | An encrypted PrivateKey. |
ProtectedPrivateKey(Address, IKdf, Byte[], ICipher, Byte[])
Loads a protected private key.
Declaration
public ProtectedPrivateKey(Address address, IKdf kdf, byte[] mac, ICipher cipher, byte[] ciphertext)
Parameters
Type | Name | Description |
---|---|---|
Address | address | The address of the protected private key. |
IKdf | kdf | A key derivation function to derive a symmetric key to decrypt a PrivateKey. |
Byte[] | mac | MAC digest to check if a derived key is correct or not. |
ICipher | cipher | A symmetric cipher to decrypt a PrivateKey. |
Byte[] | ciphertext | An encrypted PrivateKey. |
Properties
| Improve this Doc View SourceAddress
The address of the protected private key.
Declaration
public Address Address { get; }
Property Value
Type | Description |
---|---|
Address |
Cipher
A symmetric cipher to decrypt a PrivateKey.
Declaration
public ICipher Cipher { get; }
Property Value
Type | Description |
---|---|
ICipher |
Ciphertext
An encrypted PrivateKey.
Declaration
public ImmutableArray<byte> Ciphertext { get; }
Property Value
Type | Description |
---|---|
ImmutableArray<Byte> |
Kdf
A key derivation function to derive a symmetric key to decrypt a PrivateKey.
Declaration
public IKdf Kdf { get; }
Property Value
Type | Description |
---|---|
IKdf |
Mac
Declaration
public ImmutableArray<byte> Mac { get; }
Property Value
Type | Description |
---|---|
ImmutableArray<Byte> |
Methods
| Improve this Doc View SourceFromJson(String)
Loads a ProtectedPrivateKey from a JSON, according to Ethereum's Web3 Secret Storage Definition.
Declaration
public static ProtectedPrivateKey FromJson(string json)
Parameters
Type | Name | Description |
---|---|---|
String | json | A JSON string that encodes a ProtectedPrivateKey. |
Returns
Type | Description |
---|---|
ProtectedPrivateKey | A protected private key loaded from the given |
Exceptions
Type | Condition |
---|---|
InvalidKeyJsonException | Thrown when the given key data lacks some required fields or consists of wrong types. |
UnsupportedKeyJsonException | Thrown when the given key data depends on an unsupported features (e.g., KDF). |
Protect(PrivateKey, String)
Protects a bare PrivateKey using a user input
passphrase
.
Declaration
public static ProtectedPrivateKey Protect(PrivateKey privateKey, string passphrase)
Parameters
Type | Name | Description |
---|---|---|
PrivateKey | privateKey | A bare private key to protect. |
String | passphrase | A user input passphrase (i.e., password). |
Returns
Type | Description |
---|---|
ProtectedPrivateKey | A passphrase-protected private key. |
Unprotect(String)
Gets the protected PrivateKey using a user input
passphrase
.
Declaration
public PrivateKey Unprotect(string passphrase)
Parameters
Type | Name | Description |
---|---|---|
String | passphrase | A user input passphrase (i.e., password). |
Returns
Type | Description |
---|---|
PrivateKey | A bare PrivateKey. |
Exceptions
Type | Condition |
---|---|
IncorrectPassphraseException | Thrown when the given
|
MismatchedAddressException | Thrown when the unprotected PrivateKey does not match to the expected Address. |
WriteJson(Stream, Nullable<Guid>)
Dumps the cipher parameters as a JSON representation according to Ethereum's Web3 Secret Storage Definition.
Declaration
public void WriteJson(Stream stream, in Guid? id = null)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The destination for writing JSON text. |
Nullable<Guid> | id | A unique identifier, which goes to the |
WriteJson(Utf8JsonWriter, Nullable<Guid>)
Dumps the cipher parameters as a JSON representation according to Ethereum's Web3 Secret Storage Definition.
Declaration
public void WriteJson(Utf8JsonWriter writer, in Guid? id = null)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | A JSON writer which has not begun object nor array. |
Nullable<Guid> | id | A unique identifier, which goes to the |