usingInfisical.Sdk;namespace Example{classProgram{staticvoidMain(string[] args){var settings =new ClientSettings{ ClientId ="CLIENT_ID", ClientSecret ="CLIENT_SECRET",// SiteUrl = "http://localhost:8080", <-- This line can be omitted if you're using Infisical Cloud.};var infisical =newInfisicalClient(settings);var options =new GetSecretOptions{ SecretName ="TEST", ProjectId ="PROJECT_ID", Environment ="dev",};var secret = infisical.GetSecret(options); Console.WriteLine($"The value of secret '{secret.SecretKey}', is: {secret.SecretValue}");}}}
This example demonstrates how to use the Infisical C# SDK in a C# application. The application retrieves a secret named TEST from the dev environment of the PROJECT_ID project.
We do not recommend hardcoding your Machine Identity Tokens. Setting it as an environment variable would be best.
To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it’s first fetched. Each time it’s fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the “cacheTTL” option when creating the client.
var options =newCreateSecretOptions{ Environment ="dev", ProjectId ="PROJECT_ID", SecretName ="NEW_SECRET", SecretValue ="NEW_SECRET_VALUE", SecretComment ="This is a new secret",};var newSecret = infisical.CreateSecret(options);
Tag (string): A base64-encoded, 128-bit authentication tag.
Iv (string): A base64-encoded, 96-bit initialization vector.
CipherText (string): A base64-encoded, encrypted ciphertext.