String.Encoder.Decoder
8.0.2
dotnet add package String.Encoder.Decoder --version 8.0.2
NuGet\Install-Package String.Encoder.Decoder -Version 8.0.2
<PackageReference Include="String.Encoder.Decoder" Version="8.0.2" />
paket add String.Encoder.Decoder --version 8.0.2
#r "nuget: String.Encoder.Decoder, 8.0.2"
// Install String.Encoder.Decoder as a Cake Addin #addin nuget:?package=String.Encoder.Decoder&version=8.0.2 // Install String.Encoder.Decoder as a Cake Tool #tool nuget:?package=String.Encoder.Decoder&version=8.0.2
EncodeDecode Class
The EncodeDecode
class provides encryption and decryption functionality using AES (Advanced Encryption Standard) with a customizable initialization vector and passphrase. It is designed to securely encode and decode data using a salted encryption approach.
Features
- AES encryption: Securely encrypts plaintext data using the AES algorithm in CBC mode.
- AES decryption: Decodes AES-encrypted ciphertext back into plaintext.
- Salted encryption: Includes salt values for added security during encryption.
- Customizable parameters: You can specify the passphrase, salt, and initialization vector (IV) for encryption.
Requirements
- .NET 5 or higher
- A minimum passphrase length of 8 characters
- A minimum salt length of 8 characters
- An initialization vector (IV) that must be exactly 16 characters
How to Use
1. Using Dependency Injection
In your app settings add the configuration settings:
"EncodeDecodeConfiguration": {
"PasswordIterations": 2,
"Salt": "ThisIsYourSalt",
"InitVector": "@1B2c3D4e5F6g7H8",
"Passphrase": "DoNotUseForPasswords"
}
Register the service in your program.cs file
services.Configure<EncodeDecodeConfiguration>(context.Configuration.GetSection(EncodeDecodeConfiguration.Name));
services.AddScoped<IEncodeDecode, EncodeDecode>();
Inject the service where you need it:
private readonly IEncodeDecode _encryptor;
public YourClassConstructor(IEncodeDecode encrypt)
{
_encryptor = encrypt;
}
public void test()
{
Console.WriteLine("Enter Text");
var text = Console.ReadLine();
var encrypted = _encryptor.Encrypt(text);
var decrypted =_encryptor.Decrypt(encrypted);
Console.WriteLine(encrypted);
Console.WriteLine("****************");
Console.WriteLine(decrypted);
}
2. Without Dependency Injection You May Initialize the EncodeDecode
You can initialize the EncodeDecode
class with the following parameters:
string passPhrase = "YourPassphrase"; // At least 8 characters
string salt = "YourSaltValue"; // At least 8 characters
string initVector = "@1B2c3D4e5F6g7H8"; // Must be exactly 16 characters
EncodeDecode encryptor = new EncodeDecode(passPhrase, salt, initVector);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.Options (>= 8.0.2)
- System.Security.Cryptography.Encoding (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Upgraded to Net 8
Added Dependency Injection