EncryptionHelper (VB.NET)
A comprehensive utility class for data encryption and decryption operations, supporting multiple encryption algorithms and standards.
Features
- Symmetric encryption (AES)
- Asymmetric encryption (RSA)
- Hash generation
- Digital signatures
- Key management
- Password-based encryption
- Secure random number generation
Installation
Add the EncryptionHelper.vb
file to your project.
Imports JVR.Helpers
Usage Examples
Symmetric Encryption
Dim encryption As New EncryptionHelper()
' Encrypt data
Dim plainText As String = "Sensitive data"
Dim key As Byte() = encryption.GenerateAesKey()
Dim iv As Byte() = encryption.GenerateIV()
Dim encrypted As Byte() = encryption.EncryptAes(plainText, key, iv)
' Decrypt data
Dim decrypted As String = encryption.DecryptAes(encrypted, key, iv)
Asymmetric Encryption
Dim encryption As New EncryptionHelper()
' Generate key pair
Dim keyPair = encryption.GenerateRsaKeyPair()
' Encrypt with public key
Dim plainText As String = "Sensitive data"
Dim encrypted As Byte() = encryption.EncryptRsa(plainText, keyPair.PublicKey)
' Decrypt with private key
Dim decrypted As String = encryption.DecryptRsa(encrypted, keyPair.PrivateKey)
Password-Based Encryption
Dim encryption As New EncryptionHelper()
' Encrypt with password
Dim plainText As String = "Sensitive data"
Dim password As String = "MySecurePassword"
Dim encrypted As Byte() = encryption.EncryptWithPassword(plainText, password)
' Decrypt with password
Dim decrypted As String = encryption.DecryptWithPassword(encrypted, password)
API Reference
Symmetric Encryption
GenerateAesKey() As Byte()
: Generates AES keyGenerateIV() As Byte()
: Generates initialization vectorEncryptAes(plainText As String, key As Byte(), iv As Byte()) As Byte()
: Encrypts data using AESDecryptAes(cipherText As Byte(), key As Byte(), iv As Byte()) As String
: Decrypts AES encrypted data
Asymmetric Encryption
GenerateRsaKeyPair() As RsaKeyPair
: Generates RSA key pairEncryptRsa(plainText As String, publicKey As Byte()) As Byte()
: Encrypts data using RSADecryptRsa(cipherText As Byte(), privateKey As Byte()) As String
: Decrypts RSA encrypted dataSignData(data As Byte(), privateKey As Byte()) As Byte()
: Creates digital signatureVerifySignature(data As Byte(), signature As Byte(), publicKey As Byte()) As Boolean
: Verifies digital signature
Password-Based Encryption
EncryptWithPassword(plainText As String, password As String) As Byte()
: Encrypts data using passwordDecryptWithPassword(cipherText As Byte(), password As String) As String
: Decrypts password-protected dataGeneratePasswordHash(password As String, salt As Byte()) As Byte()
: Generates password hash
Key Management
ExportKey(key As Byte(), format As String) As String
: Exports encryption keyImportKey(keyData As String, format As String) As Byte()
: Imports encryption keyGenerateRandomKey(keySize As Integer) As Byte()
: Generates random key
Security Features
- Secure random number generation
- Salt generation for password hashing
- Key stretching
- Secure key storage
- Memory zeroing for sensitive data
Dependencies
- .NET 6.0 or higher
- System.Security.Cryptography
- BouncyCastle.NetCore (optional for additional algorithms)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
- Website: jvrsoftware.co.za
- Email: jvrsoftware@gmail.com or jan@jvrsoftware.co.za
Version History
- 2.0.1: Added quantum-resistant encryption algorithms
- 2.0.0: Added asymmetric encryption support
- 1.0.0: Initial release with symmetric encryption
Legal Disclaimer
This documentation and associated helper scripts are provided "as is" without warranty of any kind, either express or implied.
- The code examples and helper functions are for illustrative purposes only.
- Users should thoroughly test any implementation in their specific environment.
- The authors are not responsible for any issues or damages arising from the use of these scripts.
- Always follow security best practices and your organization's coding guidelines.
