How to Encrypt and Decrypt Data Using AES


The IPWorks Encrypt toolkit provides an easy way to encrypt and decrypt data using the AES algorithm. By setting a password and specifying input and output data, the component handles the encryption and decryption process with minimal configuration.

AES Encryption

To encrypt data, set the KeyPassword and specify the input and output files:

Aes aes = new Aes();
aes.KeyPassword = "MyKeyPassword";
aes.InputFile = "C:\\Path\\to\\UnEncryptedFile.txt";
aes.OutputFile = "C:\\Path\\to\\EncryptedFile.dat";
aes.Encrypt();

AES Decryption

To decrypt data, use the same password that was used during encryption:

Aes aes = new Aes();
aes.KeyPassword = "MyKeyPassword";
aes.InputFile = "C:\\Path\\to\\EncryptedFile.dat";
aes.OutputFile = "C:\\Path\\to\\DecryptedFile.txt";
aes.Decrypt();

Changing the Key Size

AES supports key sizes of 128, 192, and 256 bits. You can configure the key size using the KeySize configuration setting:

aes.Config("KeySize=192"); // Set Key Size to 192 bits.

Note The KeySize setting is only applicable when KeyPassword is used and the component generates the key and IV automatically.

Using Hex-Encoded Data

The component can be configured to use hex-encoded data by setting the UseHex property to true. When enabled, encrypted output will be hex-encoded, and decryption will expect hex-encoded input.

Additional Options

The AES component also supports advanced configuration options, including specifying the cipher mode, padding mode, and explicit key and IV values. Refer to the product documentation for more details on these options.

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.