Storage Project Token
The project token and encryption phrase connect your application to ByteHide's secure storage platform. Without these, you won't be able to access the storage service.
Setting the Project Token
Initialize StorageManager with your credentials:
using ByteHide.Storage;
// Initialize with project token and encryption phrase
var storage = new StorageManager("<project_token>", "<encryption_phrase>");
Obtaining Your Project Token
To get your project token, you first need to create a Storage project in the ByteHide dashboard.
Create Storage Project
If you haven't created a Storage project yet, follow our step-by-step guide: Create a Storage project
Once your project is created:
- Navigate to your Storage project dashboard
- Copy your project token from the project settings
- Use the token in your application configuration
Environment-Based Configuration
Using Environment Variables
// StorageManager will automatically read from environment variables
var storage = new StorageManager(); // Reads BYTEHIDE_STORAGE_TOKEN and BYTEHIDE_STORAGE_PHRASE
Configuration in ASP.NET Core
In appsettings.json
:
{
"ByteHide": {
"Storage": {
"ProjectToken": "your-project-token-here",
"EncryptionPhrase": "your-encryption-phrase"
}
}
}
In your application:
public void ConfigureServices(IServiceCollection services)
{
services.AddByteHideStorage(Configuration);
}
Token Behavior
Scenario | Behavior |
---|---|
Valid Token & Phrase | Full access to storage operations |
Invalid Token | InvalidOperationException thrown |
Missing Phrase | InvalidOperationException thrown |
Invalid Credentials | Storage operations will fail |
Security Best Practices
Security Note
Never hardcode tokens or encryption phrases in your source code. For maximum security, use ByteHide Secrets to manage your sensitive configuration.
Option 1: ByteHide Secrets (Recommended)
Use ByteHide Secrets to securely manage your credentials:
// Get credentials from ByteHide Secrets
var projectToken = await secretsManager.GetSecretAsync("STORAGE_TOKEN");
var encryptionPhrase = await secretsManager.GetSecretAsync("STORAGE_PHRASE");
var storage = new StorageManager(projectToken, encryptionPhrase);
ByteHide Secrets Integration
ByteHide Secrets provides enterprise-grade secret management. Learn more: ByteHide Secrets for .NET
Option 2: Environment Variables
// ❌ Don't do this
var storage = new StorageManager("bh_1234567890abcdef", "my-phrase");
// ✅ Do this instead
var storage = new StorageManager(); // Uses environment variables
Set your environment variables:
export BYTEHIDE_STORAGE_TOKEN="your-project-token"
export BYTEHIDE_STORAGE_PHRASE="your-encryption-phrase"
Validation
Verify your credentials are working:
try
{
var storage = new StorageManager("<project_token>", "<encryption_phrase>");
// Test by listing root directory
var files = await storage.ListAsync("/");
Console.WriteLine("Storage credentials are valid!");
}
catch (Exception ex)
{
Console.WriteLine($"Invalid credentials: {ex.Message}");
}