AESCrypt - AES 128 / AES 192 / AES 256 Class for ASP.NET C# with advanced settings Yet Another AES-Rijndael cryptographic class for ASP.NET C# to easily handle basic and advanced crypto tasks using 128, 192 and 256 Key Length and a whole lot of custom options & settings: Hash, Padding Mode, Cipher Mode, Salt, IV & more

Classe ASP.NET C# per il controllo e il calcolo formale del Codice Fiscale

The AES 256 / Rijndael encryption standard had a lot of ASP.NET C# implementations within the past few years: projects like BouncyCastle, SharpAESCrypt and CryptoN, just to name a few of them, are all quite simple to use and 100% working. So, why should we publish "yet another" AES 256 C# implementation class?

The answer is basically the same we usually do whenever we end up reinventing the weel, just like we did when we wrote our C# random password generator, our PDF-to-TXT and PDF-to-HTML converter and many other helper classes: we needed to do something that couldn't be done with the existing alternatives. This time we weren't looking for a "simple" implementation to handle the standard AES encryption/decryption tasks in the seamless possible way: conversely, we needed to configure some specific aspects of the AES cryptographic algorythm, such as the BlockSize, the Cipher mode, the Crypt algorithm, the Password Hashing algorithm (if any), the number of password iterations (if any), the Initialization Vector (IV), the Key Length (whenever we need it fixed), the Salt, the Padding mode, and so on.

In order to fullfill this tasks we came up with the following package, which we called AESCrypt - pretty original, isn't it? The usage is still fairly simple and very similar to the other AES-based packages - as long as you don't need to mess up with all these settings and are ok with the industry-standard defaults - yet it also has a decent (and further expandable) option class that can be configured to handle most of the encryption details.

Usage Samples

Let's start with a couple encrypt & decrypt code samples to see how it can be used in a typical back-end scenario:

As we can see, we can use either the simple mode - which uses the most common AES standards - or an advanced mode if we need more granular control.

The AESCrypt project is licensed under the Apache License 2.0 and is available on GitHub: we strongly suggest to go there in order to get the updated code.

However, in the following paragraph we'll briefly explain how it works and publish the full source code for all the package classes as it is to the present day - July 13, 2018.

Source Code

The package is made of three classes:

  • AESCrypt - the main crypto handler, containing the Encrypt and Decrypt methods and the actual implementation logic, which is built upon the AesManaged  and AESCryptOptions ASP.NET legacy classes from the SystemSecurity.Cryptography namespace.
  • AESCryptOptions - a POCO class containing the AES encrypt/decrypt options, together with their default settings.
  • AESPasswordHash - a simple ENUM containing the available options for password hash - SHA1, MD5 or None.

AESCrypt.cs

Let's start with the AESCrypt class (AESCrypt.cs file):

AESCryptOptions.cs

This is the AESCryptOptions POCO class (AESCryptOptions.cs file):

AESPasswordHash.cs

Last but not least, the AESPasswordHash enum (AESPasswordHash.cs file):

All the classes are all quite self-explanatory, hence most developers should be able to use them at will without having any major issue... you'll just have to follow the Intellisense.

That's about it: we sincerely hope that this package will help other ASP.NET developers to properly implement the AES encryption standard within their projects!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

2 Comments on “AESCrypt - AES 128 / AES 192 / AES 256 Class for ASP.NET C# with advanced settings Yet Another AES-Rijndael cryptographic class for ASP.NET C# to easily handle basic and advanced crypto tasks using 128, 192 and 256 Key Length and a whole lot of custom options & settings: Hash, Padding Mode, Cipher Mode, Salt, IV & more

    1. I’m not sure what you’re talking about: this article is all about a C# class for developers, not a finished software for end-users.

      If you need a tool to encrypt/unencrypt files on macOS Catalina using AES, I can only suggest to try some utilities such as this one:

      https://www.aescrypt.com/
      https://www.aescrypt.com/mac_aes_crypt.html

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.