A secure and efficient AES encryption and decryption demo built with .NET 10, demonstrating industry-standard cryptographic practices.
- Secure AES-256 Encryption: Advanced encryption using AES in CBC mode with PKCS7 padding.
- Dynamic IV Generation: Each encryption operation generates a cryptographically secure Initialization Vector (IV).
- Integrated IV Management: IVs are seamlessly prepended to ciphertext for convenient and secure decryption.
- Base64 Encoding: Easily store and transmit encrypted data using Base64 encoding.
- Robust Exception Handling: Proactive error detection and handling for enhanced reliability.
- Streamlined Data Processing: Efficient cryptographic operations leveraging stream-based APIs.
Here's a concise example to quickly get you started:
// Generate a secure 256-bit key
byte[] masterKey = RandomNumberGenerator.GetBytes(32);
// Encrypt your message
string encrypted = Encrypt("Your confidential message", masterKey);
Console.WriteLine($"Encrypted: {encrypted}");
// Decrypt the message
string decrypted = Decrypt(encrypted, masterKey);
Console.WriteLine($"Decrypted: {decrypted}");
- Clone this repository
git clone https://github.com/MrEshboboyev/Encryption.Demo.git
- Launch with Visual Studio
- Open the solution in Visual Studio 2022 or your preferred compatible IDE.
- Build and run the application.
- AES-256 Encryption: Optimal security with a 256-bit key size.
- CBC Mode with PKCS7 Padding: Ensures data integrity and security.
- Secure Random IV: Prevents cryptographic vulnerabilities through unique IV generation per encryption.
- Comprehensive Error Handling: Reliable cryptographic operations with robust error catching and logging.
To maximize the security and effectiveness of your encryption:
- Securely store and manage keys in protected environments.
- Avoid IV reuse; always generate a new IV for each encryption.
- Rotate encryption keys periodically.
- Use secure channels for transmitting encryption keys.
- Regularly audit and update your cryptographic libraries and dependencies.
// Read plaintext from file
string plainText = await File.ReadAllTextAsync("plainText.txt");
// Generate secure key
byte[] masterKey = RandomNumberGenerator.GetBytes(32);
// Encrypt data
string encryptedData = Encrypt(plainText, masterKey);
await File.WriteAllTextAsync("encrypted.txt", encryptedData);
Console.WriteLine("Data encrypted successfully!");
// Decrypt data
string decryptedData = Decrypt(encryptedData, masterKey);
await File.WriteAllTextAsync("decrypted.txt", decryptedData);
Console.WriteLine("Data decrypted successfully!");
- .NET 10.0 or higher
- Visual Studio 2022 or another compatible IDE
Your contributions are warmly welcomed! Feel free to:
- Submit issues
- Propose enhancements
- Create pull requests
Distributed under the MIT License. See LICENSE for more details.