Class KeyChain
A secure key chain.
Implements
Inherited Members
Namespace: Ipfs.Engine.Cryptography
Assembly: Ipfs.Engine.dll
Syntax
public class KeyChain : IKeyApi
Constructors
| Improve this Doc View SourceKeyChain(IpfsEngine)
Create a new instance of the KeyChain class.
Declaration
public KeyChain(IpfsEngine ipfs)
Parameters
Type | Name | Description |
---|---|---|
IpfsEngine | ipfs | The IPFS Engine associated with the key chain. |
Properties
| Improve this Doc View SourceOptions
The configuration options.
Declaration
public KeyChainOptions Options { get; set; }
Property Value
Type | Description |
---|---|
KeyChainOptions |
Methods
| Improve this Doc View SourceCreateAsync(String, String, Int32, CancellationToken)
Declaration
public Task<IKey> CreateAsync(string name, string keyType, int size, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | |
String | keyType | |
Int32 | size | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<IKey> |
CreateBCCertificateAsync(String, CancellationToken)
Create a X509 certificate for the specified key.
Declaration
public Task<X509Certificate> CreateBCCertificateAsync(string keyName, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | keyName | The key name. |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<Org.BouncyCastle.X509.X509Certificate> |
CreateCertificateAsync(String, CancellationToken)
Create a X509 certificate for the specified key.
Declaration
public Task<byte[]> CreateCertificateAsync(string keyName, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | keyName | The key name. |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<Byte[]> |
CreateProtectedDataAsync(String, Byte[], CancellationToken)
Encrypt data as CMS protected data.
Declaration
public Task<byte[]> CreateProtectedDataAsync(string keyName, byte[] plainText, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | keyName | The key name to protect the |
Byte[] | plainText | The data to protect. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<Byte[]> | A task that represents the asynchronous operation. The task's result is
the cipher text of the |
Remarks
Cryptographic Message Syntax (CMS), aka PKCS #7 and RFC 5652, describes an encapsulation syntax for data protection. It is used to digitally sign, digest, authenticate, and/or encrypt arbitrary message content.
ExportAsync(String, Char[], CancellationToken)
Declaration
public Task<string> ExportAsync(string name, char[] password, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | |
Char[] | password | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<String> |
FindKeyByNameAsync(String, CancellationToken)
Find a key by its name.
Declaration
public Task<IKey> FindKeyByNameAsync(string name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | The local name of the key. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<IKey> | A task that represents the asynchronous operation. The task's result is an IKey or null if the the key is not defined. |
GetPrivateKeyAsync(String, CancellationToken)
Gets the Bouncy Castle representation of the private key.
Declaration
public Task<AsymmetricKeyParameter> GetPrivateKeyAsync(string name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | The local name of key. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<Org.BouncyCastle.Crypto.AsymmetricKeyParameter> | A task that represents the asynchronous operation. The task's result is the private key as an AsymmetricKeyParameter. |
GetPublicKeyAsync(String, CancellationToken)
Gets the IPFS encoded public key for the specified key.
Declaration
public Task<string> GetPublicKeyAsync(string name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | The local name of the key. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<String> | A task that represents the asynchronous operation. The task's result is the IPFS encoded public key. |
Remarks
The IPFS public key is the base-64 encoding of a protobuf encoding containing a type and the DER encoding of the PKCS Subject Public Key Info.
See Also
| Improve this Doc View SourceImportAsync(String, String, Char[], CancellationToken)
Declaration
public Task<IKey> ImportAsync(string name, string pem, char[] password = null, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | |
String | pem | |
Char[] | password | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<IKey> |
ListAsync(CancellationToken)
Declaration
public Task<IEnumerable<IKey>> ListAsync(CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<IEnumerable<IKey>> |
ReadProtectedDataAsync(Byte[], CancellationToken)
Decrypt CMS protected data.
Declaration
public Task<byte[]> ReadProtectedDataAsync(byte[] cipherText, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Byte[] | cipherText | The protected CMS data. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<Byte[]> | A task that represents the asynchronous operation. The task's result is the plain text byte array of the protected data. |
Remarks
Cryptographic Message Syntax (CMS), aka PKCS #7 and RFC 5652, describes an encapsulation syntax for data protection. It is used to digitally sign, digest, authenticate, and/or encrypt arbitrary message content.
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | When the required private key, to decrypt the data, is not foumd. |
RemoveAsync(String, CancellationToken)
Declaration
public Task<IKey> RemoveAsync(string name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<IKey> |
RenameAsync(String, String, CancellationToken)
Declaration
public Task<IKey> RenameAsync(string oldName, string newName, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | oldName | |
String | newName | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task<IKey> |
SetPassphraseAsync(SecureString, CancellationToken)
Sets the passphrase for the key chain.
Declaration
public Task SetPassphraseAsync(SecureString passphrase, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
SecureString | passphrase | |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
Remarks
The passphrase
is used to generate a DEK (derived encryption
key). The DEK is then used to encrypt the stored keys.
Neither the passphrase
nor the DEK are stored.
Exceptions
Type | Condition |
---|---|
UnauthorizedAccessException | When the |