Encrypting and Decrypting with AES

IPWorks Encrypt makes it very easy to encrypt and decrypt data. This article will detail the process of performing AES encryption and decryption.

AES Encryption

AES Encryption is as simple as selecting a KeyPassword and specifying the data to be encrypted. Please see the following example:

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

AES Decryption is just as simple as AES Encryption. All that is needed is the encrypted data and the KeyPassword that was used during the 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

The AES Encryption algorithm supports keys of size 128, 192, and 256. You can specify the key size to be used for Encryption and Decryption via the "KeySize" configuration setting as detailed below.

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

Note: The KeySize configuration option is only valid when KeyPassword is set and the component automatically generates the Key and IV values.

Configuring AES to use Hex-encoded strings

The AES component can be instructed to use Hex-encoded strings for its encryption and decryption operations. When the UseHex property is set to true, the Encrypt operation will Hex-encode the encrypted data. Similarly, if the UseHex property is set to true, the Decrypt operation will assume that the encrypted data has been Hex-encoded.

Additional Options

The AES component supports a variety of options to offer more control over the encryption and decryption mechanisms used. Options include the ability to specify the Cipher Mode and Padding Mode used, as well as specifying the Key and IV values. Please see the IPWorks Encrypt help documentation for more information on these options.

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