OpenSSL is a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS) protocols as well as a full-strength general purpose cryptography library.
The versions of OpenSSL library at biicode are:
Both versions are generated from this github repo.
Encrypting with MD5 and SHA1
This example shows how to use the cryptography feature of OpenSSL using a MD5 and SHA1 algorithm to encrypt a string.
Creating a new project
Create a new simple layout project with the name of your block and copy the code below:
$ bii init mysslproject -L $ cd mysslproject $ # Copy both files inside
The MD5 example encrypts a string "happy":
.. literalinclude:: /_static/code/cpp/examples/openssl/md5.cpp :language: cpp :emphasize-lines: 1
Next, we'll use a similar code to encrypt a "hello world!" string with SHA1:
.. literalinclude:: /_static/code/cpp/examples/openssl/sha1.cpp :language: cpp :emphasize-lines: 1
Manage your dependencies
Take a look at the
#include pointing to OpenSSL. Type bii deps to see unresolved dependencies:
$ bii deps INFO: Processing changes... your_user/mysslproject depends on: system: stdio.h string.h unresolved: openssl/md5.h openssl/sha.h
Let's edit now the biicode.conf file generated in the project folder. Add your
[requirements] depending on the version you want and map your
[requirements] lasote/openssl: 3 [includes] openssl/*.h: lasote/openssl/include
Retrieve your unresolved dependencies:
$ bii find INFO: Processing changes... INFO: Downloading files from: lasote/openssl INFO: Downloading files from: biicode/cmake INFO: Saving files from: lasote/openssl ...
Build the project
Now execute bii build.
$ bii build
Go to /bin directory and execute the binaries:
$ cd bin $./examples_openssl_md5 md5 digest: 56ab24c15b72a457069c5ea42fcfc640
That output is the MD5 hash value of your encrypted string.
$./examples_openssl_sha1 sha1 digest: 2d5ec68b0d061c75db
And that is the SHA1 hash value for the "hello world!" string.
Develop your project
You can develop your own project with OpenSSL. Choose your version or switch between them using the :ref:`block track feature<dependencies_block_track>`.
Just modify the
[requirements] section in the biicode.conf file of your block's folder:
To depend on OpenSSL 1.0.1:
[requirements] lasote/openssl: 2
To depend on OpenSSL 1.0.2:
[requirements] lasote/openssl(v1.0.2): 1
Open and build
This example is already in biicode: examples/openssl.
Just open and build it to give it a quick try.
Create a new project and open the block:
$ bii init mysslproject $ cd mysslproject $ bii open examples/openssl
Now build and run the examples:
$ cd bin $./examples_openssl_md5 md5 digest: 56ab24c15b72a457069c5ea42fcfc640 $./examples_openssl_sha1 sha1 digest: 2d5ec68b0d061c75db