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)

Git shallow cloning stuff

so after you use shallow cloning in git using –depth 1, if you call git pull you will find that git will pull all changes not just –depth 1.

to honour the –depth 1 from cloning we call call git pull with the same depth:

git pull –depth 1 origin master

life saving stuff

Quick cloning of kernel mainline

git clone –depth 1 https://github.com/torvalds/linux.git linux_mainline

using github as it’s a mirror of mainline and depending where you’re accessing the internet from, much faster.

the –depth 1 will limit the history to 1 commit back I believe. If you’d need to view more than that then you can probably use

git log — [filename]


TypeScript – Method Overloading

export class HtmlElementFactory {
// method overloading – sort off… pretty weird
static CreateGeneric(elementName: string): HTMLElement;
static CreateGeneric(elementName: string, elementId: string,
innerHTML:string,attributes: Array<HtmlElementAttributes>) : HTMLElement;
static CreateGeneric(elementName: string, elementId?: string,
innerHTML?:string, attributes?: Array<HtmlElementAttributes>) : HTMLElement {
var htmlElement = document.createElement(elementName);
htmlElement.id = (elementId) ? elementId : "";
htmlElement.innerHTML = (innerHTML) ? innerHTML : "";
if (attributes) {
for (let attr of attributes)
htmlElement.setAttribute(attr.key, attr.value);
return htmlElement;

Shallow cloning git repos

Just making a note of something that might be very useful going forward. I needed to use `​git clone –depth 10 ` to clone a repo but only get the last 10 commits of it.

It helped me cloning the linux repo many years back on a horrible internet connection. This essentially doesn’t clone the entire repo’s history, however, it would clone all files and history relevant to the last 10 commits.

Cloud flare – Page Rules

Just remembered that you can make use of Cloud flare’s Page Rules feature to handle URL forwarding from the domain your managing to another domain hosted else where on the internet. I think you also need to setup a CNAME record to make this work:

I needed http://twisum.adhir.co.za to redirect to https://young-mesa-51990.herokuapp.com .


this simply allows me during dev to work with friendly urls without signing up for a paid plan on heroku to add custom domains. You only receive 3 free Page Rules with the free Cloud flare account though.

Just recording a simple example of Tree Traversal

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnTreeDS
public class Node
public string Name { get; set; }
public bool Visited { get; set; }
public List<Node> Children { get; set; } = new List<Node>();
class Program
_ R_
/ | \
1 2 3
/ | \
4 5 6
public static void TraverseFn(Node currentNode)
currentNode.Visited = true;
Console.WriteLine("Visited: " + currentNode.Name);
foreach (var child in currentNode.Children)
static void Main(string[] args)
var Root = new Node() { Name = "Root" };
var child1 = new Node() { Name = "1" };
child1.Children.Add(new Node() { Name = "4" });
child1.Children.Add(new Node() { Name = "5" });
child1.Children.Add(new Node() { Name = "6" });
Root.Children.Add(new Node() { Name = "2" });
Root.Children.Add(new Node() { Name = "3" });

view raw


hosted with ❤ by GitHub