This tutorial will guide you on how to hash a string by using OpenSSL’s SHA512 hash function. This tutorial will create two C++ example files which will compile and run in Ubuntu environment.

  1. Here are the openssl SHA512 sample source code.

    Example #1: sha512_sample1.cpp


    Example #2: sha512_sample2.cpp

  2. Let’s try to compile both sample cpp files and you should observe the following output screenshot.
    ~$ gcc sha512_sample1.cpp -o sample1 -lcrypto
    ~$ ./sample1
    SHA512 digest: 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
    ~$ gcc sha512_sample2.cpp -o sample2 -lcrypto
    ~$ ./sample2
    SHA512 digest: 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
    Note: -lcrypto will include the crypto library from openssl