LFInteractive Docs
  • Programming Documentation
  • C#
    • Installing Visual Studio
    • Understanding C#
      • Namespaces
      • Classes
      • Enum
      • Variables
        • Static Types
        • Primitive Types
        • Access Modifiers
        • Variables vs Properties
        • Nullable Variables
      • Getters and Setters
      • Solution vs Project
      • Struct vs Class
      • Coding Conventions
      • Tasks and Async
        • Parallel Tasks
      • Methods
      • PreProcessor Statements
    • Creating Your First Console App
      • Class Library
        • Models
          • File Model
          • Result Model
        • Controllers
          • File Controller
          • File System Controller
      • Console App
        • Nuget Packages
        • Main Method
    • Minecraft.NET
      • Minecraft.NET Library
      • Modrinth.NET Library
      • CurseForge.NET Library
      • Fabric.NET Library
    • Common Lib
      • Strings
      • Advanced Network Client
      • Advanced Timer
      • Advanced File Info
      • Configuration File
      • Application Config
      • Database File
      • Crypt Class
  • C++
    • Networking
      • Windows Socket (Client)
    • cclip
    • VCPKG
    • spdlog
      • Getting Started
      • Patterns
Powered by GitBook
On this page
  • Class Overview
  • Constructor
  • Properties
  • Methods
  • Private Methods
  • Examples

Was this helpful?

Edit on GitHub
  1. C#
  2. Common Lib

Crypt Class

PreviousDatabase FileNextC++

Last updated 1 year ago

Was this helpful?

The Crypt class is a part of the Chase CommonLib library developed by LFInteractive LLC. This class is designed for encrypting and decrypting strings and files using the AES encryption algorithm. It provides methods to encrypt and decrypt data and allows you to specify a custom salt for added security.

Class Overview

Namespace

namespace Chase.CommonLib.Math;

License

The Crypt class is licensed under the .

Summary

A class for encrypting and decrypting strings and files using the AES encryption algorithm.

Constructor

Crypt()

Creates a new instance of the Crypt class with a random salt based on the current machine.

public Crypt();

Crypt(string salt)

Creates a new instance of the Crypt class with the specified salt.

  • salt: A custom salt value used for encryption and decryption.

public Crypt(string salt);

Properties

Salt

Gets or sets the salt used for encryption and decryption.

public string Salt { get; set; }

Methods

Encrypt(string text)

Encrypts the specified text using AES encryption.

  • text: The text to be encrypted.

Returns the encrypted text as a Base64-encoded string.

public string Encrypt(string text);

Encrypt(string path, string output)

Encrypts the content of a file and writes the encrypted data to an output file.

  • path: The path to the input file.

  • output: The path to the output file where the encrypted data will be written.

public void Encrypt(string path, string output);

Decrypt(string path, string output)

Decrypts the content of a file and writes the decrypted data to an output file.

  • path: The path to the input file containing encrypted data.

  • output: The path to the output file where the decrypted data will be written.

public void Decrypt(string path, string output);

Decrypt(string text)

Decrypts the specified Base64-encoded text using AES decryption.

  • text: The Base64-encoded text to be decrypted.

Returns the decrypted text.

public string Decrypt(string text);

Private Methods

GetSaltBytes()

Gets the salt bytes derived from the Salt property.

private byte[] GetSaltBytes();

Examples

Example 1: Encrypting and Decrypting Text

// Create a Crypt instance with a custom salt
Crypt crypt = new Crypt("MyCustomSalt");

// Encrypt a text
string encryptedText = crypt.Encrypt("SensitiveData123");

// Decrypt the encrypted text
string decryptedText = crypt.Decrypt(encryptedText);

Console.WriteLine("Original Text: SensitiveData123");
Console.WriteLine("Encrypted Text: " + encryptedText);
Console.WriteLine("Decrypted Text: " + decryptedText);

Example 2: Encrypting and Decrypting Files

// Create a Crypt instance with a custom salt
Crypt crypt = new Crypt("MyCustomSalt");

// Encrypt a file
crypt.Encrypt("input.txt", "encrypted_output.dat");

// Decrypt the encrypted file
crypt.Decrypt("encrypted_output.dat", "decrypted_output.txt");

This documentation provides an overview of the Crypt class, its constructor, properties, methods, and includes example code demonstrating how to use it for text and file encryption and decryption.

GPL-3.0 license