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
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);
Akeyless Gateway URL should be one of the following:
https://akeyless.example.com:8081: The address of a private Akeyless Gateway deployment. Note that it uses port 8081.
https://akeyless.example.com:8080/v2: The address of a private Akeyless Gateway deployment that uses the legacy API port with the /v2 path prefix.
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.
Add the following dependency to your project:
dotnet add package akeyless-dotnet-cloudid
Add the following statements to your project:
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;
The following examples show how you can create, retrieve, and delete a secret.
tokenvalue you received during authentication.
var createSecretBody = new CreateSecret(name: "netcore", value: "value", token: token); CreateSecretOutput createSecretResult = instance.CreateSecret(createSecretBody);
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"]);
var deleteItemBody = new DeleteItem(name: "netcore", deleteImmediately: true, deleteInDays: -1, token: token); DeleteItemOutput deleteItemResult = instance.DeleteItem(deleteItemBody);
For a detailed API reference, see here.
Updated 2 months ago