/

Quick Start

The ByteHide.ToolBox SDK provides tools for managing secrets.

The ByteHide.ToolBox SDK is available as a NuGet package. You can install it using the NuGet Package Manager in Visual Studio or via the command line with the following command:

Environment Variables

The ByteHide.ToolBox SDK uses environment variables to store secrets. You can create environment variables in your operating system or use an app.config file to store them.

These are the environment variables that you need to set:

  • ByteHide.Secrets.Environment: The environment in which the secrets are stored. For example, development, production, etc.
  • ByteHide.Secrets.Token: The token is your project token. You can find it in the ByteHide panel.

If you haven't obtained your PROJECT TOKEN yet, please retrieve it from the ByteHide panel before proceeding.

How to get my project token

Usage with Global Environment Variables

Once the package is installed, you can use the ByteHide.ToolBox SDK in your application as follows:

namespace Sample;

internal class Program
{
    internal static void Main()
    {
        // Initialize the secrets manager using the global environment variables
        Bytehide.ToolBox.Secrets.ManagerSecrets.Initialize();
        var secrets = Bytehide.ToolBox.Products.Secrets;

        // Set a secret
        secrets.Set("my-secret-name", "my-secret-value");

        // Get a secret
        var value = secrets.Get("my-secret-name");

        Console.WriteLine($"my secret is: {value}");
        Console.ReadLine();
    }
}

In the example above, we are using the ManagerSecrets class to manage secrets. You can also use the Products class to manage secrets. The Products class is a static class that provides access to all the products of the ByteHide.ToolBox SDK. You can simplify the code by declaring using Bytehide.ToolBox.Secrets;.

Usage with Local Environment Variables

You can also use local environment variables to store secrets. You can use an app.config file.

Your app.config file should look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
        <add key="ByteHide.Secrets.Environment" value="development"/>
        <add key="ByteHide.Secrets.Token" value="e34762f8-8ad6-0000-0000-000000000000"/>
    </appSettings>
</configuration>

Once you put the file in the root of your project, you can use the ByteHide.ToolBox SDK in your application as follows:

namespace Sample;

internal class Program
{
    internal static void Main()
    {
        // Initialize the secrets manager using the local environment
        Bytehide.ToolBox.Secrets.ManagerSecrets.Initialize(true);
        var secrets = Bytehide.ToolBox.Products.Secrets;

        // Set a secret
        secrets.Set("my-secret-name", "my-secret-value");

        // Get a secret
        var value = secrets.Get("my-secret-name");

        Console.WriteLine($"my secret is: {value}");
        Console.ReadLine();
    }
}

In the example above, the initialization of the secrets manager is done using the local environment variables. The true parameter in the Initialize method indicates this.

Remember that you must put your environment variables in the root of your project to use the ByteHide.ToolBox SDK.

Usage with Manual Environment Variables

You can also use manual environment variables to store secrets. Set the environment variables in your operating system as follows:

namespace Sample;

internal class Program
{
    internal static void Main()
    {
        // Initialize the secrets manager using manual environment variables
        Bytehide.ToolBox.Secrets.ManagerSecrets.Initialize("development");
        var secrets = Bytehide.ToolBox.Products.Secrets;

        // Set a secret
        secrets.Set("my-secret-name", "my-secret-value");

        // Get a secret
        var value = secrets.Get("my-secret-name");

        Console.WriteLine($"my secret is: {value}");
        Console.ReadLine();
    }
}

In the example above, the initialization of the secrets manager is done using manual environment variables. The parameter in the Initialize method is the environment.

Usage in Unsecure Mode

You can also use the ByteHide.ToolBox SDK in unsecure mode. In this mode, you don't need to set environment variables. Use the ManagerSecrets class to manage secrets as shown below:

namespace Sample;

internal class Program
{
    internal static void Main()
    {
        // Initialize the secrets manager using unsecure method
        Bytehide.ToolBox.Secrets.ManagerSecrets.UnsecureInitialize("development", "e34762f8-8ad6-0000-0000-000000000000");
        var secrets = Bytehide.ToolBox.Products.Secrets;

        // Set a secret
        secrets.Set("my-secret-name", "my-secret-value");

        // Get a secret
        var value = secrets.Get("my-secret-name");

        Console.WriteLine($"my secret is: {value}");
        Console.ReadLine();
    }
}

In the example above, the initialization of the secrets manager is done using the unsecure method. The parameters in the UnsecureInitialize method are the environment and the project token.

The unsecure mode is not recommended for production environments. This is only for testing purposes.

Additionally, you can find detailed logs of the protection process in the logs folder located in your assembly directory.

Previous
Install