Learning to use AES encryption

I’ve started working on a simple credentials manager app that runs on the console and I wanted the credentials that are kept on file to be encrypted for obvious reasons. The app is written in C++ and I needed to find and work with an appropriate encryption library.

I’ve tried using two libraries: OpenSSL and Tiny-AES-C. OpenSSL is meant to be a hardened production ready library and it’s trusted by many. Using the libCrypto API that comes with OpenSSL proved to be a challenge to get working with though. I guess with such a powerful library you need to understand all setup and config it provides and I didn’t have the time and energy to dig too deep on that.

Giving up on OpenSSL, I tried my luck with Tiny-AES-C as it’s a far simpler C library that implements just the AES encryption algorithm. AES seems to be the “most” secure algorithm at this time (2020) so seems like a good option to go with. You can find the Tiny-AES-C project on GitHub: https://github.com/kokke/tiny-AES-c. You’d need to compile the library to use it in your project. Reading the Makefile in the project indicates various build options one of which is to build the lib target:

Tiny-AES-C Makefile: target for building the static library

Using Tiny-AES-C took an attempt or two but I’ve managed to create a sample app that handles the following:

  • Padding plain text to block length of 16
  • Encrypting plain text
  • Decrypting plain text
  • Identifying and removing padding from decrypted text

My example Tiny-AES-C usage project can be found here https://github.com/AdhirRamjiawan/Tiny-AES-C-Example

Some considerations to have after getting my example app working:

  • You need to ensure that the buffer size used for encryption/decryption is a multiple of 16 else you’ll get strange buffer overrun issues.
  • With AES CBC algorithm you need to employ some padding mechanism. Padding should be done to ensure block size of 16, so the total length of the text to be encrypted should be a multiple of 16.
  • The Key and IV (Initial Vector) parameters should NOT be kept in your code. I’ve kept it in the example app as a frame of reference going forward. Ideally you should consider using an environment variable or maybe another file containing this info.
  • Ideally the Key should be derived from a passphrase or similar (need to expand on this)
  • Ideally the IV should be generated using a psuedorandom number generator. (need to expand on this)


Posted

in

,

by

Tags:

Comments

16 responses to “Learning to use AES encryption”

  1. 创建个人账户 Avatar

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  2. Kisisel Hesap Olusturun Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.com/join?ref=IXBIAFVY

  3. Registrera Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://accounts.binance.com/register-person?ref=JW3W4Y3A

  4. binance Registrera dig Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  5. binance Sign Up Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  6. anm"ala dig till binance Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  7. binance referral bonus Avatar

    Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/sv/register-person?ref=GQ1JXNRE

  8. binance h"anvisning Avatar

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.info/register-person?ref=IXBIAFVY

  9. Create a free account Avatar

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  10. Binance创建账户 Avatar

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  11. binance registration Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  12. създаване на профил в binance Avatar

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  13. Binance账户创建 Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.info/register?ref=L4EUT9FG

  14. binance h"anvisningsbonus Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  15. binance Registrera Avatar

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  16. binance anm"alan Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

Leave a Reply

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