diff --git a/docs/sdks/languages/csharp.mdx b/docs/sdks/languages/csharp.mdx new file mode 100644 index 000000000..70c583a86 --- /dev/null +++ b/docs/sdks/languages/csharp.mdx @@ -0,0 +1,391 @@ +--- +title: "C#" +icon: "C#" +--- + +If you're working with C#, the official [Infisical C# SDK](https://github.com/Infisical/sdk/tree/main/languages/csharp) package is the easiest way to fetch and work with secrets for your application. + +## Basic Usage + +```cs +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](/platform/identities/overview). Setting it as an environment variable would be best. + + +# Installation + +Run `npm` to add `@infisical/sdk` to your project. + +```console +$ dotnet add package Infisical.Sdk +``` +# Configuration + +Import the SDK and create a client instance with your [Machine Identity](/platform/identities/universal-auth). + +```cs +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! + } + } +} +``` + +### ClientSettings methods + + + + + Your machine identity client ID. + + + Your machine identity client secret. + + + + An access token obtained from the machine identity login endpoint. + + + + Time-to-live (in seconds) for refreshing cached secrets. + If manually set to 0, caching will be disabled, this is not recommended. + + + + Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`) + + + + + +### Caching + +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. + +## Working with Secrets + +### client.ListSecrets(options) + +```cs +var options = new ListSecretsOptions +{ + ProjectId = "PROJECT_ID", + Environment = "dev", + Path = "/foo/bar", + AttachToProcessEnv = false, +}; + +var secrets = infisical.ListSecrets(options); +``` + +Retrieve all secrets within the Infisical project and environment that client is connected to + +#### Parameters + + + + + The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. + + + + The project ID where the secret lives in. + + + + The path from where secrets should be fetched from. + + + + Whether or not to set the fetched secrets to the process environment. If true, you can access the secrets like so `System.getenv("SECRET_NAME")`. + + + + Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference) + + + + + +### client.GetSecret(options) + +```cs +var options = new GetSecretOptions + { + SecretName = "AAAA", + ProjectId = "659c781eb2d4fe3e307b77bd", + Environment = "dev", + }; +var secret = infisical.GetSecret(options); +``` + +Retrieve a secret from Infisical. + +By default, `GetSecret()` fetches and returns a shared secret. + +#### Parameters + + + + + The key of the secret to retrieve. + + + The project ID where the secret lives in. + + + The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. + + + The path from where secret should be fetched from. + + + The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". + + + + +### client.CreateSecret(options) + +```cs +var options = new CreateSecretOptions { + Environment = "dev", + ProjectId = "PROJECT_ID", + + SecretName = "NEW_SECRET", + SecretValue = "NEW_SECRET_VALUE", + SecretComment = "This is a new secret", +}; + +var newSecret = infisical.CreateSecret(options); +``` + +Create a new secret in Infisical. + +#### Parameters + + + + + The key of the secret to create. + + + The value of the secret. + + + The project ID where the secret lives in. + + + The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. + + + The path from where secret should be created. + + + The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". + + + + +### client.UpdateSecret(options) + +```cs +var options = new UpdateSecretOptions { + Environment = "dev", + ProjectId = "PROJECT_ID", + + SecretName = "SECRET_TO_UPDATE", + SecretValue = "NEW VALUE" +}; + +var updatedSecret = infisical.UpdateSecret(options); +``` + +Update an existing secret in Infisical. + +#### Parameters + + + + + The key of the secret to update. + + + The new value of the secret. + + + The project ID where the secret lives in. + + + The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. + + + The path from where secret should be updated. + + + The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". + + + + +### client.DeleteSecret(options) + +```cs +var options = new DeleteSecretOptions +{ + Environment = "dev", + ProjectId = "PROJECT_ID", + SecretName = "NEW_SECRET", +}; + +var deletedSecret = infisical.DeleteSecret(options); +``` + +Delete a secret in Infisical. + +#### Parameters + + + + + The key of the secret to update. + + + The project ID where the secret lives in. + + + The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. + + + The path from where secret should be deleted. + + + The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". + + + + +## Cryptography + +### Create a symmetric key + +Create a base64-encoded, 256-bit symmetric key to be used for encryption/decryption. + +```cs +var key = infisical.CreateSymmetricKey(); +``` + +#### Returns (string) +`key` (string): A base64-encoded, 256-bit symmetric key, that can be used for encryption/decryption purposes. + +### Encrypt symmetric +```cs +var options = new EncryptSymmetricOptions +{ + Plaintext = "Infisical is awesome!", + Key = key, +}; + +var encryptedData = infisical.EncryptSymmetric(options); +``` + +#### Parameters + + + + + The plaintext you want to encrypt. + + + The symmetric key to use for encryption. + + + + +#### Returns (object) +`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. + +### Decrypt symmetric +```cs +var decryptOptions = new DecryptSymmetricOptions +{ + Key = key, + Ciphertext = encryptedData.Ciphertext, + Iv = encryptedData.Iv, + Tag = encryptedData.Tag, +}; + +var decryptedPlaintext = infisical.DecryptSymmetric(decryptOptions); +``` + +#### Parameters + + + + The ciphertext you want to decrypt. + + + The symmetric key to use for encryption. + + + The initialization vector to use for decryption. + + + The authentication tag to use for decryption. + + + + +#### Returns (string) +`Plaintext` (string): The decrypted plaintext. + diff --git a/docs/sdks/languages/go.mdx b/docs/sdks/languages/go.mdx deleted file mode 100644 index 3baca3b0f..000000000 --- a/docs/sdks/languages/go.mdx +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "Go" -icon: "golang" ---- - -Coming soon. - -Star our GitHub repository to stay updated [cross-language SDK](https://github.com/Infisical/sdk) GitHub repository to stay updated. diff --git a/docs/sdks/languages/java.mdx b/docs/sdks/languages/java.mdx index 7c3ec5599..36c339c9b 100644 --- a/docs/sdks/languages/java.mdx +++ b/docs/sdks/languages/java.mdx @@ -121,7 +121,7 @@ SecretElement[] secrets = client.listSecrets(options); Retrieve all secrets within the Infisical project and environment that client is connected to -### Methods +#### Methods @@ -165,7 +165,7 @@ Retrieve a secret from Infisical. By default, `getSecret()` fetches and returns a shared secret. -### Methods +#### Methods @@ -203,7 +203,7 @@ CreateSecretResponseSecret newSecret = client.createSecret(createOptions); Create a new secret in Infisical. -### Methods +#### Methods @@ -245,7 +245,7 @@ UpdateSecretResponseSecret updatedSecret = client.updateSecret(options); Update an existing secret in Infisical. -### Methods +#### Methods @@ -286,7 +286,7 @@ DeleteSecretResponseSecret deletedSecret = client.deleteSecret(options); Delete a secret in Infisical. -### Methods +#### Methods @@ -307,3 +307,76 @@ Delete a secret in Infisical. + +## Cryptography + +### Create a symmetric key + +Create a base64-encoded, 256-bit symmetric key to be used for encryption/decryption. + +```java +String key = client.createSymmetricKey(); +``` + +#### Returns (string) +`key` (string): A base64-encoded, 256-bit symmetric key, that can be used for encryption/decryption purposes. + +### Encrypt symmetric +```java +EncryptSymmetricOptions options = new EncryptSymmetricOptions(); +options.setKey(key); +options.setPlaintext("Infisical is awesome!"); + +EncryptSymmetricResponse encryptedData = client.encryptSymmetric(options); +``` + +#### Methods + + + + + The plaintext you want to encrypt. + + + The symmetric key to use for encryption. + + + + +#### Returns (object) +`tag (getTag())` (string): A base64-encoded, 128-bit authentication tag. +`iv (getIv())` (string): A base64-encoded, 96-bit initialization vector. +`ciphertext (getCipherText())` (string): A base64-encoded, encrypted ciphertext. + + +### Decrypt symmetric +```java +DecryptSymmetricOptions decryptOptions = new DecryptSymmetricOptions(); +decryptOptions.setKey(key); +decryptOptions.setCiphertext(encryptedData.getCiphertext()); +decryptOptions.setIv(encryptedData.getIv()); +decryptOptions.setTag(encryptedData.getTag()); + +String decryptedString = client.decryptSymmetric(decryptOptions); +``` + +#### Methods + + + + The ciphertext you want to decrypt. + + + The symmetric key to use for encryption. + + + The initialization vector to use for decryption. + + + The authentication tag to use for decryption. + + + + +#### Returns (string) +`Plaintext` (string): The decrypted plaintext. \ No newline at end of file diff --git a/docs/sdks/languages/node.mdx b/docs/sdks/languages/node.mdx index 9179e2f9d..3e6b0cae9 100644 --- a/docs/sdks/languages/node.mdx +++ b/docs/sdks/languages/node.mdx @@ -84,12 +84,12 @@ Import the SDK and create a client instance with your [Machine Identity](/docume clientSecret: "YOUR_CLIENT_SECRET", logLevel: LogLevel.Error }); - ```` + ``` -### Parameters +#### Parameters @@ -138,7 +138,7 @@ const secrets = await client.listSecrets({ Retrieve all secrets within the Infisical project and environment that client is connected to -### Parameters +#### Parameters @@ -180,7 +180,7 @@ Retrieve a secret from Infisical. By default, `getSecret()` fetches and returns a shared secret. -### Parameters +#### Parameters @@ -255,7 +255,7 @@ const updatedApiKey = await client.updateSecret({ Update an existing secret in Infisical. -### Parameters +#### Parameters @@ -315,3 +315,73 @@ Delete a secret in Infisical. + +## Cryptography + +### Create a symmetric key + +Create a base64-encoded, 256-bit symmetric key to be used for encryption/decryption. + +```js +const key = client.createSymmetricKey(); +``` + +#### Returns (string) +`key` (string): A base64-encoded, 256-bit symmetric key, that can be used for encryption/decryption purposes. + +### Encrypt symmetric +```js +const { iv, tag, ciphertext } = await client.encryptSymmetric({ + key: key, + plaintext: "Infisical is awesome!", +}) +``` + +#### Parameters + + + + + The plaintext you want to encrypt. + + + The symmetric key to use for encryption. + + + + +#### Returns (object) +`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. + +### Decrypt symmetric +```js +const decryptedString = await client.decryptSymmetric({ + key: key, + iv: iv, + tag: tag, + ciphertext: ciphertext, +}); +``` + +#### Parameters + + + + The ciphertext you want to decrypt. + + + The symmetric key to use for encryption. + + + The initialization vector to use for decryption. + + + The authentication tag to use for decryption. + + + + +#### Returns (string) +`plaintext` (string): The decrypted plaintext. diff --git a/docs/sdks/languages/php.mdx b/docs/sdks/languages/php.mdx deleted file mode 100644 index bf861acb4..000000000 --- a/docs/sdks/languages/php.mdx +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "PHP" -icon: "php" ---- - -Coming soon. - -Star our GitHub repository to stay updated [cross-language SDK](https://github.com/Infisical/sdk) GitHub repository to stay updated. diff --git a/docs/sdks/languages/python.mdx b/docs/sdks/languages/python.mdx index 8420e6e77..68cabaee9 100644 --- a/docs/sdks/languages/python.mdx +++ b/docs/sdks/languages/python.mdx @@ -60,7 +60,7 @@ client = InfisicalClient(ClientSettings( )) ``` -### Parameters +#### Parameters @@ -110,7 +110,7 @@ client.listSecrets(options=ListSecretsOptions( Retrieve all secrets within the Infisical project and environment that client is connected to -### Parameters +#### Parameters @@ -149,7 +149,7 @@ value = secret.secret_value # get its value By default, `getSecret()` fetches and returns a shared secret. If not found, it returns a personal secret. -### Parameters +#### Parameters @@ -187,7 +187,7 @@ api_key = client.createSecret(options=CreateSecretOptions( Create a new secret in Infisical. -### Parameters +#### Parameters @@ -225,7 +225,7 @@ client.updateSecret(options=UpdateSecretOptions( Update an existing secret in Infisical. -### Parameters +#### Parameters @@ -262,7 +262,7 @@ client.deleteSecret(options=DeleteSecretOptions( Delete a secret in Infisical. -### Parameters +#### Parameters @@ -283,3 +283,79 @@ Delete a secret in Infisical. + +## Cryptography + +### Create a symmetric key + +Create a base64-encoded, 256-bit symmetric key to be used for encryption/decryption. + +```py +key = client.createSymmetricKey() +``` + +#### Returns (string) +`key` (string): A base64-encoded, 256-bit symmetric key, that can be used for encryption/decryption purposes. + +### Encrypt symmetric +```py +encryptOptions = EncryptSymmetricOptions( + key=key, + plaintext="Infisical is awesome!" +) + +encryptedData = client.encryptSymmetric(encryptOptions) +``` + +#### Parameters + + + + + The plaintext you want to encrypt. + + + The symmetric key to use for encryption. + + + + +#### Returns (object) +`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. + +### Decrypt symmetric +```py +decryptOptions = DecryptSymmetricOptions( + ciphertext=encryptedData.ciphertext, + iv=encryptedData.iv, + tag=encryptedData.tag, + key=key +) + +decryptedString = client.decryptSymmetric(decryptOptions) + + +``` + +#### Parameters + + + + The ciphertext you want to decrypt. + + + The symmetric key to use for encryption. + + + The initialization vector to use for decryption. + + + The authentication tag to use for decryption. + + + + +#### Returns (string) +`plaintext` (string): The decrypted plaintext. diff --git a/docs/sdks/languages/ruby.mdx b/docs/sdks/languages/ruby.mdx deleted file mode 100644 index 2836f7043..000000000 --- a/docs/sdks/languages/ruby.mdx +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "Ruby" -icon: "gem" ---- - -Coming soon. - -Star our GitHub repository to stay updated [cross-language SDK](https://github.com/Infisical/sdk) GitHub repository to stay updated. diff --git a/docs/sdks/languages/rust.mdx b/docs/sdks/languages/rust.mdx deleted file mode 100644 index d535ad527..000000000 --- a/docs/sdks/languages/rust.mdx +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "Rust" -icon: "rust" ---- - -Coming soon. - -Star our GitHub repository to stay updated [cross-language SDK](https://github.com/Infisical/sdk) GitHub repository to stay updated. diff --git a/docs/sdks/overview.mdx b/docs/sdks/overview.mdx index aca673c49..28631a77d 100644 --- a/docs/sdks/overview.mdx +++ b/docs/sdks/overview.mdx @@ -18,17 +18,8 @@ From local development to production, Infisical SDKs provide the easiest way for Manage secrets for your Java application on demand - - Manage secrets for your Ruby application on demand - - - Manage secrets for your Go application on demand - - - Manage secrets for your Rust application on demand - - - Manage secrets for your PHP application on demand + + Manage secrets for your C#/.NET application on demand