This article will learn about Advanced Encryption Standard (AES) in C#. I thought I would start a little series into using some of cryptography with AES in C#. Cryptography and Encryption is something part that most developers working with enterprise applications will come across, in especially if you work in the financial services industry. You can try aes decrypt c# example and aes encrypt c# example in end the article with step by step.

Cryptography is a fascinating subject and design of these algorithms is very interesting, don’t recommend using an algorithm that you have designed yourself. Algorithms in practice now have been through lots of analysis by experts both in private industries and governments all around the world trying to find faults and weaknesses, so you are much better to using these recommended systems.

The main algorithms fall include 2 categories, There are Symmetric encryption and Asymmetric encryption. Symmetric encryption contains algorithms that are based solely on an encryption key. For example, if you encrypt some plaintext with Key1 you get a cipher text out the other end. If you then decrypt the cipher text with the same key (Key1) you will get back to the original plaintext.

Asymmetric encryption works by having 2 keys, a public and private key. These keys are mathematically derived from each other. The public key can be used by anyone and the private key has to be kept secret. I will talk about asymmetric encryption and more specifically RSA in another post.

For this article I am going to look at the AES symmetric algorithm. AES stands for the Advanced Encryption Standard. This was a competition winner when the National Institute of Standards and Technology ran a contest to replace the already broken DES algorithm.

What I will show in this article is a good practical implementation of AES in .NET. We will start with the following interface. The interface contains 2 methods, Encrypt and Decrypt. They methods take cipher text/plaintext and an encryption key. For Example: AES_DECRYPT(fieldname, “yourkey“)

In this tutorial we will practice example Decrypt and Encrypt with inserting,selection methods in Mysql. We will insert data from .Net to Mysql with Encryption and selecting data from Mysql with decryption.

Let’s following this step for know about Encryption and Decryption with AES:

  1. Create database in mysql with name “test” and create table with name “title” ,look the below for example.


  1. Create a new application project. In Visual Studio, on the menu click File> New > Project. For more details, see the following menu on the display.


  1. Then will appear the window New Project like the look below.


  1. Write down the name of the project that will be created on a field Name. Specify the directory storage project by accessing the field Location. Next, give the name of the solution in the Solution Name. Then click OK.


  1. Create a new windows form like the below.


  1. Create a new class for connection database and write the following program listing :

  1. Next step, Back to windows form and view code to write the following program listing:

  1. After you write down the program listings, press the F5 key to run the program and if you successfull connect your database the result is :



You can see Advanced Encryption Standard (AES) in C# from Github project in Here.

Thank you for reading this article about Advanced Encryption Standard (AES) in C#, I hope this article is useful for you. Visit My Github about .Net Csharp in Here

Advanced Encryption Standard (AES) in C#

Leave a Reply

Your email address will not be published. Required fields are marked *