The #1 rule of cryptography: Don’t invent your own!

OK wiseman, now what? You want to add crypto to your program but you don’t want to code it all yourself. I’ll show you three libraries that make it possible. The choice will be yours as to which one to use.

For this example I wanted to write a simple function that accepts a std::string message and returns hex encoded SHA-1 hash. I picked the following libraries: Crypto++, WolfSSL, and Botan. All three made it pretty easy, and I don’t want to get into the business of picking winners and losers, but… Botan mad it a breeze and I think it will be my choice going forward 🙂

crypto.cpp:

Message: Vorbrodt’s C++ Blog @ https://vorbrodt.blog
Digest : 24BCAC1359AA8B773D38D6A05B22BB43DAB5B8E5

Message: Vorbrodt’s C++ Blog @ https://vorbrodt.blog
Digest : 24BCAC1359AA8B773D38D6A05B22BB43DAB5B8E5

Message: Vorbrodt’s C++ Blog @ https://vorbrodt.blog
Digest : 24BCAC1359AA8B773D38D6A05B22BB43DAB5B8E5

Program output.

4 Replies to “The #1 rule of cryptography”

  1. Hello, I’m new in this cryptography library world, I have almost the same code for a hash function, but when I compile my function with “g++-9.1 main.cpp -o salida -lcryptopp” y just get “Undefined symbols for architecture x86_64:” I just don’t get where is the problem

    1. What you describe is a linker error, not compile time issue. Looks like you’re not linking with the right library. If you email me your source code main.cpp file, I can try building it on my Linux machine and send you back the proper linker flags for G++ command.

      My email address is: [email protected]

      BTW, what is your environment? What flavor and version of Linux are you using?

Leave a Reply