using Infisical.Sdk;namespace Example{ class Program { static void Main(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 = new InfisicalClient(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.
Import the SDK and create a client instance with your Machine Identity.
Copy
using Infisical.Sdk;namespace Example{ class Program { static void Main(string[] args) { var settings = new ClientSettings { ClientId = "CLIENT_ID", ClientSecret = "CLIENT_SECRET", }; var infisical = new InfisicalClient(settings); // <-- Your SDK instance! } }}
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.
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.
var decryptOptions = new DecryptSymmetricOptions{ Key = key, Ciphertext = encryptedData.Ciphertext, Iv = encryptedData.Iv, Tag = encryptedData.Tag,};var decryptedPlaintext = infisical.DecryptSymmetric(decryptOptions);