Class Crypto
Provides methods for performing .
Inheritance
Namespace: Hyperledger.Indy.CryptoApi
Assembly: Hyperledger.Indy.Sdk.dll
Syntax
public static class Crypto : Object
Methods
AnonCryptAsync(String, Byte[])
Declaration
public static Task<byte[]> AnonCryptAsync(string theirVk, byte[] message)
Parameters
Type | Name | Description |
---|---|---|
System.String | theirVk | |
System.Byte[] | message |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Byte[]> |
AnonDecryptAsync(Wallet, String, Byte[])
Declaration
public static Task<byte[]> AnonDecryptAsync(Wallet wallet, string myVk, byte[] encryptedMessage)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | |
System.String | myVk | |
System.Byte[] | encryptedMessage |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Byte[]> |
AuthCryptAsync(Wallet, String, String, Byte[])
Declaration
public static Task<byte[]> AuthCryptAsync(Wallet wallet, string myVk, string theirVk, byte[] message)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | |
System.String | myVk | |
System.String | theirVk | |
System.Byte[] | message |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Byte[]> |
AuthDecryptAsync(Wallet, String, Byte[])
Declaration
public static Task<AuthDecryptResult> AuthDecryptAsync(Wallet wallet, string myVk, byte[] message)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | |
System.String | myVk | |
System.Byte[] | message |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<AuthDecryptResult> |
CreateKeyAsync(Wallet, String)
Creates a key in the provided wallet.
Declaration
public static Task<string> CreateKeyAsync(Wallet wallet, string keyJson)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | The wallet to create the key in. |
System.String | keyJson | The JSON string describing the key. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | An asynchronous System.Threading.Tasks.Task<> that resolves to a string containing the verification key of the generated key-pair. |
Remarks
The keyJson
parameter must contain a JSON object although all properties of the object are optional. The schema
the object must conform to are as follows:
{
"seed": string, // Optional (if not set random one will be used); Seed information that allows deterministic key creation.
"crypto_type": string, // Optional (if not set then ed25519 curve is used); Currently only 'ed25519' value is supported for this field.
}
The seed
member is optional and is used to specify the seed to use for key creation - if this parameter is not set then a random seed will be used.
The crypto_type
member is also optional and will default to ed25519 curve if not set.
note
At present the crypto_type member only supports the value 'ed22519'.
Exceptions
Type | Condition |
---|---|
InvalidStructureException | Thrown if the value passed to the |
GetKeyMetadataAsync(Wallet, String)
Gets the user defined metadata stored against a key-pair in the specified wallet.
Declaration
public static Task<string> GetKeyMetadataAsync(Wallet wallet, string verKey)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | The wallet containing the key-pair. |
System.String | verKey | The verification key of the key-pair. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | An asynchronous System.Threading.Tasks.Task<> that resolves to a string containing the metadata associated with the key-pair. |
Remarks
If no metadata is stored against the specified key-pair null will be returned.
Exceptions
Type | Condition |
---|---|
WalletValueNotFoundException | Thrown if the wallet does not contain a key-pair matching the provided |
SetKeyMetadataAsync(Wallet, String, String)
Sets user defined metadata for a key-pair in the specified wallet.
Declaration
public static Task SetKeyMetadataAsync(Wallet wallet, string verKey, string metadata)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | The wallet containing the key. |
System.String | verKey | The verification key of the key pair. |
System.String | metadata | The metadata to set. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | An asynchronous System.Threading.Tasks.Task that completes when the operation completes. |
Remarks
Any existing metadata stored for the key-pair will be replaced.
Exceptions
Type | Condition |
---|---|
WalletValueNotFoundException | Thrown if the wallet does not contain a key-pair matching the provided |
SignAsync(Wallet, String, Byte[])
Signs the provided message with the provided key.
Declaration
public static Task<byte[]> SignAsync(Wallet wallet, string myVk, byte[] message)
Parameters
Type | Name | Description |
---|---|---|
Wallet | wallet | The wallet containing the key-pair to sign with. |
System.String | myVk | The verification key of the key-pair to sign with. |
System.Byte[] | message | The message to sign |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Byte[]> | An asynchronous System.Threading.Tasks.Task<> that resolves to a byte array containing the signature. |
Remarks
The key provided as the myVk
parameter must have previously been stored in the wallet
using
the CreateKeyAsync(Wallet, String) method or the Hyperledger.Indy.SignusApi.Signus.CreateAndStoreMyDidAsync(Hyperledger.Indy.WalletApi.Wallet,System.String) method.
note
To use DID keys with this method call the Hyperledger.Indy.SignusApi.Signus.KeyForDidAsync(Hyperledger.Indy.PoolApi.Pool,Hyperledger.Indy.WalletApi.Wallet,System.String) with the desired DID to get
its verification key which can be used as the myVk
parameter when calling this method.
Exceptions
Type | Condition |
---|---|
WalletValueNotFoundException | Thrown if |
VerifyAsync(String, Byte[], Byte[])
Verifies a message signature with a verification key.
Declaration
public static Task<bool> VerifyAsync(string theirVk, byte[] message, byte[] signature)
Parameters
Type | Name | Description |
---|---|---|
System.String | theirVk | The verification key belonging to the party that signed the message. |
System.Byte[] | message | The message that was signed. |
System.Byte[] | signature | The signature for the message. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | An asynchronous System.Threading.Tasks.Task<> that, when the operation completes, resolves to true if the signature was valid, otherwise false. |