C# .NET Core SDK

The Akeyless C# .NET SDK makes it easy for you to integrate your .NET applications, libraries, or scripts with the Akeyless Vault Platform secret management services. The C# code examples below show a typical sequence of how to integrate secrets into your application.

Installation

To add the Akeyless C# .NET SDK as a dependency in your project, run:

dotnet add package akeyless --version <package-version>

👍

For a full list of the existing versions, see here.

Configuration

📘

The following example uses these using statements:

  • using akeyless.Client;
  • using akeyless.Api;
  • using akeyless.Model;

The first step is to create and configure an instance of the Akeyless Client:

Configuration config = new Configuration();
config.BasePath = "<Akeyless Gateway URL>";
var instance = new V2Api(config);

The Akeyless Gateway URL should be one of the following:

Authentication

The Akeyless C# .NET SDK supports multiple authentication methods. The following example shows API Key authentication:

var authBody = new Auth(accessId: "p-1234", accessKey: "<redacted>");
AuthOutput authResult = instance.Auth(authBody);
String token = authResult.Token;

The token received in this step must be used in every call that requires authentication.

Usage Examples

The following examples show how you can create, retrieve, and delete a secret.

👍

Use the token value you received during authentication.

Create a Secret

var createSecretBody = new CreateSecret(name: "netcore", value: "value", token: token);
CreateSecretOutput createSecretResult = instance.CreateSecret(createSecretBody);

Retrieve a Secret

List<String> secrets = new List<String>();
secrets.Add("netcore");
var getSecretValueBody = new GetSecretValue(names: secrets, token: token);
Dictionary<string, string> getSecretValueResult = instance.GetSecretValue(getSecretValueBody);
Console.WriteLine(getSecretValueResult["netcore"]);

Delete a Secret

var deleteItemBody = new DeleteItem(name: "netcore", deleteImmediately: true, deleteInDays: -1, token: token);
DeleteItemOutput deleteItemResult = instance.DeleteItem(deleteItemBody);

API Reference

For a detailed API reference, see here.