Bytehide.Storage 1.0.0.5

dotnet add package Bytehide.Storage --version 1.0.0.5                
NuGet\Install-Package Bytehide.Storage -Version 1.0.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bytehide.Storage" Version="1.0.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bytehide.Storage --version 1.0.0.5                
#r "nuget: Bytehide.Storage, 1.0.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Bytehide.Storage as a Cake Addin
#addin nuget:?package=Bytehide.Storage&version=1.0.0.5

// Install Bytehide.Storage as a Cake Tool
#tool nuget:?package=Bytehide.Storage&version=1.0.0.5                
   _____ __                            
  / ___// /_____  _________ _____ ____ 
  \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \
 ___/ / /_/ /_/ / /  / /_/ / /_/ /  __/
/____/\__/\____/_/   \__,_/\__, /\___/ 
                          /____/       

Bytehide Storage SDK Sample

This sample demonstrates how to use the Bytehide Storage SDK for performing various tasks such as uploading, downloading, compressing, and encrypting files. The example includes:

  • Load embedded resources.
  • Compress and decompress files locally.
  • Upload and download files with encryption and compression.
  • Handle text and JSON files securely.
  • Zero-knowledge encryption.

Prerequisites

  • Install the Bytehide.Storage NuGet package.
  • You will need a project token from the Bytehide panel.
  • Create an environment with the following structure:
    • /<bucket_name>/images/ for image uploads.
    • /<bucket_name>/texts/ for text uploads.
    • /<bucket_name>/models/ for model uploads.

Installation

Add the ByteHide.Storage SDK to your .NET project via NuGet:

NuGet\\Install-Package Bytehide.Storage

Integration

Once the package is installed, start integrating it into your project.

Code Overview

1. Initialize the Storage Manager

Initialize the StorageManager with your project token.

var storage = new StorageManager();

🔴 Note: Create your environment variables:

  • BYTEHIDE_STORAGE_TOKEN your project token.
  • BYTEHIDE_STORAGE_PHRASE_ENCRYPTION your encryption phrase.

Or

var storage = new StorageManager("<project_token>", "<phrase_encryption>");

🔴 Note: Consider using a secure method to store the project token and encryption phrase, such as ByteHide Secrets.

Quantum Algorithm Support

The library supports various quantum algorithms designed to protect data against quantum computing threats. These algorithms adhere to post-quantum cryptographic standards. Below is a list of the supported algorithms, along with brief descriptions of each:

public enum QuantumAlgorithmType
{
    Kyber512,
    Kyber768,
    Kyber1024,
    Sntrup761,
    FrodoKem1344Shake,
    MlKem512,
    MlKem768,
    MlKem1024
}

To set a quantum algorithm, use the following code:

var storage = new StorageManager(QuantumAlgorithmType.Kyber1024);

🔴 Note: The default quantum algorithm is Kyber1024.

Algorithm Descriptions

  1. Kyber512, Kyber768, Kyber1024

    Kyber is a lattice-based Key Encapsulation Mechanism (KEM), currently recommended by NIST. Variants 512, 768, and 1024 represent increasing levels of security, with Kyber1024 offering the highest level of protection, ideal for applications requiring maximum resistance to quantum attacks.

  2. Sntrup761

    Based on NTRU combined with R-LWE (Ring Learning With Errors), Sntrup761 is a fast and secure KEM scheme resistant to quantum attacks. It is designed to balance performance with security, making it suitable for resource-constrained environments.

  3. FrodoKem1344Shake

    Part of the FrodoKEM family, this algorithm is based on the LWE problem without using specific algebraic structures. FrodoKem1344Shake leverages the SHAKE hash function to provide a high level of security, suited for scenarios where security is prioritized over speed.

  4. MlKem512, MlKem768, MlKem1024

    The MlKem algorithms focus on secure key encapsulation mechanisms using optimized algebraic structures. Versions 512, 768, and 1024 offer different security levels, with MlKem1024 as the most robust, suitable for critical applications demanding high security.

2. Uploading an Image with Encryption and Compression using Embedded Resources Helper

This section shows how to load an image file from the project's embedded resources. ResourceManagerHelper.GetResourceAsBytes()

var image = ResourceManagerHelper.GetResourceAsBytes(Assembly.GetExecutingAssembly(), "Sample.Resources.Images.photo0.jpg");

if (image == null || image.Length == 0)
{
     Console.WriteLine("Failed to load the image from resources.");
     return;
}
bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Set("photo.jpg", image);

Async

bool uploaded = await storage
                  .In("<bucket_name>/images")
                  .SetAsync("photo.jpg", image).Result;

3. Uploading an Image from assembly

This section demonstrates how to upload an image to the storage bucket from the assembly. FromAssembly()

bool uploaded = storage
                  .In("<bucket_name>/images")
                  .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<path_to_image>");

4. Uploading from a file

This section demonstrates how to upload a file to the storage bucket from the local file system. FromFile()

bool uploaded = storage
                  .In("<bucket_name>/images")
                  .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
                  .In("<bucket_name>/texts")
                  .FromFile("file.txt", "<path_to_file>/file.txt");

5. Uploading a File with Compression

This section demonstrates how to upload a file with compression. Compress()

bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Compress()
                  .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Compress()
                  .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
                  .In("<bucket_name>/texts")
                  .Compress()
                  .FromFile("file.txt", "<path_to_file>/file.txt");

6. Uploading a File with Encryption

This section demonstrates how to upload a file with encryption. Encrypt()

bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Encrypt()
                  .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Encrypt()
                  .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
                  .In("<bucket_name>/texts")
                  .Encrypt()
                  .FromFile("file.txt", "<path_to_file>/file.txt");

7. Uploading a File with Encryption and Compression

This section demonstrates how to upload a file with encryption and compression. Encrypt() and Compress()

bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Compress()
                  .Encrypt()
                  .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
                  .In("<bucket_name>/images")
                  .Compress()
                  .Encrypt()
                  .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
                  .In("<bucket_name>/texts")
                  .Compress()
                  .Encrypt()
                  .FromFile("file.txt", "<path_to_file>/file.txt");

8. Uploading a File with Quantum Encryption and Compression

This section demonstrates how to upload a file with quantum encryption and compression. EncryptWithQuantum()

bool uploaded = storage
                  .In("<bucket_name>/images")
                  .EncryptWithQuantum()
                  .Compress()
                  .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
                  .In("<bucket_name>/images")
                  .EncryptWithQuantum()
                  .Compress()
                  .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
                  .In("<bucket_name>/texts")
                  .EncryptWithQuantum()
                  .Compress()
                  .FromFile("file.txt", "<path_to_file>/file.txt");

9. Uploading a Large Text File

Upload a large text file and apply compression and encryption. The maximum file size is 5 GB.

var largeText = Encoding.UTF8.GetBytes(new string('A', 10000000));
storage
     .In("<bucket_name>/texts")
     .Compress()
     .Encrypt()
     .Set("payload.txt", largeText);

With Quantum Encryption

var largeText = Encoding.UTF8.GetBytes(new string('A', 10000000));
storage
     .In("<bucket_name>/texts")
     .Compress()
     .EncryptWithQuantum()
     .Set("payload.txt", largeText);

10. Downloading an Image and Saving to Disk

storage
     .In("<bucket_name>/images")
     .SaveToDisk("photo.jpg", "<path_to_downloaded_image>/photo.jpg");

11. Downloading Text Files

Download a text file and save it to disk.

storage
     .In("<bucket_name>/texts")
     .SaveToDisk("payload.txt", "<path_to_downloaded_text>/payload.txt");

Or

storage
     .SaveToDisk("<bucket_name>/texts/payload.txt", "<path_to_downloaded_text>/payload.txt");

Download the text file as a string.

string text = storage
                 .In("<bucket_name>/texts")
                 .GetText("payload.txt");

Or

string text = storage
                  .GetText("<bucket_name>/texts/payload.txt");

Async

string text = await storage
                  .In("<bucket_name>/texts")
                  .GetTextAsync("payload.txt").Result;

Download the text file as a byte array.

byte[] data = storage
                  .In("<bucket_name>/texts")
                  .GetBytes("payload.txt");

Or

byte[] data = storage
                  .GetBytes("<bucket_name>/texts/payload.txt");

Async

string text = await storage
                  .In("<bucket_name>/texts")
                  .GetBytesAsync("payload.txt").Result;

12. Uploading and Downloading JSON Data

Upload a JSON string as a text file.

const string json = "{\"name\":\"John Doe\",\"age\":30}";
var uploaded = storage
                  .In("<bucket_name>/models")
                  .Compress()
                  .Encrypt()
                  .Set("json.txt", json);
// Define a simple class Foo for demonstration purposes
private class Foo
{
    private string Name { get; }
    private int Age { get; }

    public Foo(string name, int age)
    {
        Name = name;
        Age = age;
    }

    public override string ToString() => $"Name: {Name}, Age: {Age}";
}

Download the JSON and deserialize it to a custom Foo object.

var data = storage
               .In("<bucket_name>/models")
               .Get<Foo>("json.txt"); 

Async

var data = await storage
                     .In("<bucket_name>/models")
                     .GetAsync<Foo>("json.txt").Result;
Output

Name: John Doe, Age: 30

Download the JSON as a string.

string text = storage
                  .In("<bucket_name>/models")
                  .GetText("json.txt");

Async

string text = await storage
                        .In("<bucket_name>/models")
                        .GetTextAsync("json.txt").Result;
Output

{"name":"John Doe","age":30}

Notes

The compression and encryption methods can be chained in any order. The order of the methods does not matter.

storage
     .In("<bucket_name>/images")
     .Encrypt()
     .Compress()
     .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
storage
     .In("<bucket_name>/images")
     .Compress()
     .Encrypt()
     .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");

If encryption and quantum encryption are used together, it will be applied the last one.

Encryption:

storage
     .In("<bucket_name>/images")
     .EncryptWithQuantum()
     .Encrypt()
     .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");

Quantum Encryption:

storage
     .In("<bucket_name>/images")
     .Encrypt()
     .EncryptWithQuantum()
     .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
  • The compressed files are detected automatically and decompressed during download.
  • The encrypted files are detected automatically and decrypted during download.

License

ByteHide.Storage is licensed under MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0.5 98 11/18/2024
1.0.0.3 85 11/18/2024
1.0.0.2 95 11/18/2024
1.0.0.1 95 11/18/2024
1.0.0 91 11/18/2024