Class PreSharedKey
A secret (symmetric) key shared among some entities.
Inherited Members
Namespace: PeerTalk.Cryptography
Assembly: PeerTalk.dll
Syntax
public class PreSharedKey
Remarks
This is specifically used for nodes in a private network.
Properties
| Improve this Doc View SourceLength
The length of the key's value.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
Int32 | The length in bits. |
Value
The key value.
Declaration
public byte[] Value { get; set; }
Property Value
Type | Description |
---|---|
Byte[] | The value as a byte array. |
Methods
| Improve this Doc View SourceExport(TextWriter, String)
Write the key to text stream.
Declaration
public void Export(TextWriter text, string format = "base16")
Parameters
Type | Name | Description |
---|---|---|
TextWriter | text | A text writer. |
String | format | Determines how the key Value is formatted. Can be "base16" or "base64". Defaults to "base16". |
Remarks
The key is writen as three lines (1) the codec name "/key/swarm/psk/1.0.0/" (2) the base encoding "/base16/" or "/base64/", (3) the key value in the base encoding
Fingerprint()
Gets an ID for the key.
Declaration
public byte[] Fingerprint()
Returns
Type | Description |
---|---|
Byte[] | A byte array that can be used as an identifier for the key. |
Remarks
C# implementation of the GO code at https://github.com/libp2p/go-libp2p-pnet/blob/bed5e6afdf9099121029f6fb675be12a50196114/fingerprint.go#L10.
Generate(Int32)
Generate a new value of the specified length.
Declaration
public PreSharedKey Generate(int length = 256)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The length in bits of the new key value, defaults to 256. |
Returns
Type | Description |
---|---|
PreSharedKey | this for a fluent design. |
Import(TextReader)
Read the key from the text stream.
Declaration
public void Import(TextReader text)
Parameters
Type | Name | Description |
---|---|---|
TextReader | text | A text reader. |