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.


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.




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:


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.

Using Cloud ID

Add the following dependency to your project:

dotnet add package akeyless-dotnet-cloudid

Add the following statements to your project:

using akeyless.Cloudid;

Authenticate using Cloud ID:

// Use azure_ad/aws_iam/gcp, according to your cloud provider
var accessType = "aws_iam";
var cloudIdProvider = CloudIdProviderFactory.GetCloudIdProvider(accessType);
var cloudId = cloudIdProvider.GetCloudId();

Auth auth = new Auth();
auth.AccessId = "<your access id>";
auth.AccessType = accessType;
auth.CloudId = cloudId;

AuthOutput result = api.Auth(auth);
string token = result.Token;

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>();
var getSecretValueBody = new GetSecretValue(names: secrets, token: token);
Dictionary<string, string> getSecretValueResult = instance.GetSecretValue(getSecretValueBody);

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.