When it comes to guarantee data confidentiality on the wire or on the disk we cannot be exempt to know how to use cryptography: this post provides a quick guide of both symmetric and asymmetric cryptography along with an overview of their bricks: RSA and DSA keys, Elliptic Curves keys, PGP Keys, Message Digest, HMAC, digital signature and encipherment. The aim is to provide the necessary terms and concepts to understand how to operate with cryptographic tools, providing examples with openssl.



It is a set of data used to feed cryptographic routines: they are called keys since same way as physical keys lock and unlock things, cryptographic keys lock and unlock cryptographic objects. There are two kind of keys:

  • symmetric – a single key
  • asymmetric – a pair of keys: one is private, the other is public

Symmetric (often called secret) keys and private keys must never and ever be disclosed since whoever has access to those keys can use (or abuse) them. We should make our best to avoid having our keys compromised: a compromised key is a key that got stolen or disclosed to unauthorized people.

A compromised key can be used to sign documents as if they were signed from the real owner of the key.

We must take all the measures necessary to avoid the key to be compromised, such as

  • limiting read access to the file containing the key
  • encrypting the key using a password-protected symmetric encryption function

Encryption should always be used, either if we are storing the key into a filesystem or we are transmitting the key to a peer.

There's only one kind of key that as its name suggests is public: the so-called public key of an asymmetric key pair.


It is the scrambling of data so that it appears without an understandable meaning: scrambled data are said to be encrypted, whereas the original data are said to be plain-text (or unencrypted). There are two types of encryption: symmetric and asymmetric encryption, based on the type of keys used.

Basically there are two families of encryption algorithms:

  • block ciphers, such as DES, 3DES, Blowfish, IDEA, RC2, RC5, AES, ... : data gets encrypted by fixed size blocks (64, 128,...)
  • stream ciphers, such as RC4, SALSA, SOSEMANUK, PANAMA, ...: operate on each byte of data, so requiring fewer resources than block ciphers

Typically, stream ciphers are faster than block ciphers, although some of them are considered less secure than block ciphers. For example, RFC 7465 prohibits the use of RC4 in all versions of TLS. However, because they perform faster than block ciphers, stream ciphers are certainly interesting when it comes to stream data over the wire.

Block ciphers have several operating modes - provide a thorough explanation of them would be too theoretical for this post so I only list them providing a summary description:

  • Electronic Codebook Mode (ECB): data is handled in blocks of 64bits, one at a time, encrypting every block with the same key, padding the last chunk of data if it does not completely fit the last block. There's a risk with brute-force attacks and, in addition to that, an attacker can easily modify the order of the blocks, thus preventing the peer from being able to decrypt the message.
  • Cipher-Block Chaining (CBC): perform a xor of the data of the current block with the one of the previous one. Since there's not a preceding block, he first block uses an Initialization Vector (IV) for the xor block. The IV is randomly generated as new each time the encipher process is started, so to cope with replay-attacks. 
  • Cipher Feedback (CFB): use some optimizations to be a little bit more performing, making it more suitable than the others to encrypt data streams
  • Output Feedback mode (OFB): very similar to CFB, it does not propagate errors of transmission of bits, but it is more vulnerable to an attack that modifies the flow of the messages.
  • Counter (CTR): a mode specifically developed to be used with ATM and IPSec.
Malicious people may try to decrypt data by exploiting algorithms weakness and brute-force attacks: a brute-force attack consists in trying to force by continuous trials. However if strong keys, high-quality passwords and modern encryption methods are used, they should resist brute force attacks. Take in account that chances to violate encrypted contents increase as years go by, since computers become more and more powerful. For this reason it is wise to always keep current on cryptography standards in order to be able to find your weakness and fix them before breaches happen.

Message Digest

The solution to the integrity check problem

It is the outcome of deriving a bit array of a fixed size from the original data using a mathematical algorithm that cannot be reverted (it is called cryptographic hash). Examples of cryptographic hash functions are:

  • MD-4, MD-5, RIPEMD-160
  • SHA-1, SHA-256, SHA-512

Message digests are generated using a symmetric key and are suitable to implement the so called Message Authentication Code (MAC): this is the process of validating data integrity by verifying that the MAC code calculated at the receiving party does match the one provided by the sender: if it doesn't, it means that data has been tampered.

Hash-based Message Authentication Code

The solution to the authentication problem

Message digests let you verify that the message has not been tampered, but they do not guarantee that the received message does actually come from the entity that is supposed to be the author instead of from an impostor. This limitation is addressed by the Hash-based Message Authentication Code (HMAC) algorithm: it has been specifically designed to enable the parties to establish a trusted channel and to agree on the key and the MAC algorithm to use. This resolves the authentication problem: but there is still a missing thing: since both parties calculate the MAC using the shared key, you cannot say from a MAC which one of the parties did generate it. So HMAC are suitable for integrity check and authentication, but not for non-repudiation, since we cannot clearly identify who generated the MAC.


The solution to the non-repudiation problem

Asymmetric cryptography addresses the non-repudiation problem: when digitally signing  the sender encrypts the MAC using its own private key. Any receiver can easily verify that the message comes from us by decrypting it using the sender's public key, and then verify the integrity of the message validating the MAC. Conversely from HMAC, each party has its own private key, and so the signature can clearly identify who signed the message.

Symmetric Cryptography

Symmetric cryptography relies on symmetric keys, so only one secret key is used by both parties to perform cryptographic operations, such as encrypting, decrypting or Message Code Authentication.

Let's see it in action

We use openssl solely for providing examples, since it is really handy to explain concepts - when it comes to encrypt things in real life you'd better to use PGP. We'll have a deep dive on PGP on a future post.

Secret Key

It is a key that contains random data: we can easily generate one as follows: for example, to create 256 random bits:

openssl rand -out key.bin 32

we specified 32 since rand uses bytes: 256/8=32.

Encrypting contents

This is the most straightforward type of encryption: both parties use the same key to encrypt and decrypt. Despite this kind of encryption is easier to implement and offers better performance if compared with asymmetric encryption, it is cumbersome to keep secure since you have to deliver copies of the key in situations such as:

  • as time goes by, ideally you should generate a new key and provide it to all the parties to replace the old one
  • you should provide the key to any new party that get added
  • if one of the party withdraws or get compromised you should generate a new key and provide it to all the parties

Commonly used symmetric encryption algorithms include:

  • AES
  • Blowfish
  • Camellia
  • Idea
  • DES, 3DES
  • RC4, RC5, RC6
  • Twofish

In this example, we encrypt using AES-256 using cfb8 mode of operation: as we already saw, the mode of operation is the way to repeatedly apply a cipher’s single-block operation to securely transform amounts of data larger than a block.

cfb8 is only one of the modes of operation supported by the AES algorithm: as we already saw, other supported modes for example are cbc, cfb, ofb, and gcm.

So to  hide patterns in the encrypted data, we use an Initialization Vector (IV). It is needed to both encrypt and decrypt data, and the best practice is to use a new IV at each encryption operation: if you decrypt the file to modify it, and then you encrypt it back you should generate a new IV. In this particular use case, we need an hexadecimal IV:

IV=$(openssl rand -hex 16)

if you want to have a look at it:

echo ${IV}

we are ready to encrypt files: as an example let's encrypt the contents of /etc/issue file into issue.dat

openssl enc -aes-256-cfb8 -in /etc/issue -pbkdf2 -iv ${IV} -out issue.dat

it asks for the password to be used for the encryption:

enter aes-256-cfb8 encryption password:
Verifying - enter aes-256-cfb8 encryption password:

The -pbkdf2 parameters tells openssl to generate and use a derived key: this is generated by repeatedly calling a pseudo-random function using a salt.

We can now try to decrypt what we have encrypted: the command is as follows:

openssl enc -d -aes-256-cfb8 -in issue.dat -out issue.txt -pbkdf2 -iv ${IV}

it asks for the password to be used for decrypting:

enter aes-256-cfb8 decryption password:

If we prefer not use a password, we can use generate a key file using "openssl rand ... " as we saw before and provide its path using the -key command option:

openssl rand -out key.bin 32
openssl enc -aes-256-cfb8 -in /etc/issue -k file:key.bin -pbkdf2 -iv ${IV} -out issue.dat

the command for decrypting the file is as follows:

openssl enc -d -aes-256-cfb8 -in issue.dat  -k file:key.bin -out issue.txt -pbkdf2 -iv ${IV}

Asymmetric Cryptograpy

Asymmetric cryptography relies on a pair of keys: a private key and a public key, mathematically related to the private one. It's very difficult to derive the private key by knowing only the related public key: this means that it should take hundreds if not thousands of years to compute it (considering the computational capabilities at when you generated the key).

But bear in mind that computational capabilities increase during the years, … that's why the recommended key size has changed during the years (at the time of writing this post, it is 2048-4096 bits for RSA or DSA keys if you want to stay safe).

As for the key size, asymmetric and symmetric keys behave very differently: an asymmetric key requires much more bits to provide the same strength of a symmetric key. For example a 80 bit symmetric key has more or less the same strength of a 1024 bit asymmetric key, or again, a 128 bit symmetric key has more or less the same strength of a 3072 bit asymmetric key.

For this reason, asymmetric cryptography is used only to encrypt and decrypt the random symmetric session key that is used to perform the encryption of the actual data.

This asymmetric cryptography is easier to keep secure if compared to symmetric cryptography: the key shared with the other parties is public data, so no special care is needed for both delivering and storing them. In addition to that, we should strive to protect only our key - the private one, conversely from symmetric encryption, where we have to strive to keep the key secure on all of the parties

The true pitfall of asymmetric cryptography is that you need a way ensure that the public key you received is actually the one that belongs to the entity you think it should - a need that has been addresses by using digital certificates.

Asymmetric key pairs can be used for the following purposes:

Authentication systems rely on authentication algorithms that validate the Private Key used by the connecting entity to authenticate against the related Public Key: if there's a match, then the identity of the caller is considered verified. Since the key used by the authenticator is public, it can even be published on an online repository and the authenticator can fetch it only when needed..
encrypt contents
Data are encrypted with an algorithm that uses the public key: the encrypted messages can be decrypted using the same algorithm, but only using the private key related to the public key used while encrypting (here I'm quite simplifying things, since only the session key is encrypted this way – more on this topic later on) .
So for example Foo user sends its public key to Bar user. Bar user can now encrypt a message using Foo user's public key and send the encrypted data to Foo user. Foo user can decrypt the message by using its own private key. Even here we didn't disclose anything valuable: Foo user gave Bar its public data. Even if Bar would disclose the foo public key there would be no consequences.
sign contents
After generating the MAC of the data that have to be signed, the MAC gets encrypted using the private key. The peer can verify the signature by decrypting it using the public key related to the key used to sign and validating the MAC.
Getting back to Foo and Bar users, Foo can digitally sign a message (usually in clear) using his private key. When Bar receives the message he can verify the signature using Foo's public key.
Signature can provide what is called non-repudiation, that is a proof that what is written, besides haven't been tampered, actually belongs to who digitally signed it.




The RSA (Rivest–Shamir–Adleman, from the surnames of Ron Rivest, Adi Shamir and Leonard Adleman) is one of the oldest cryptographic systems (it has been published in 1977). It's security relies on the practical difficulty of factoring the product of two large prime numbers, the "factoring problem".

Let see how to generate and RSA key pair: for example let's generate a 2048 bit AES256 encrypted (-aes256 parameter) RSA key:

openssl genrsa -aes256 -out key.priv 2048

we can inspect the key as follows:

openssl rsa -in key.priv -noout -text

after typing the unlocking (decrypting) password, the output is as follows:

RSA Private-Key: (2048 bit, 2 primes)
publicExponent: 65537 (0x10001)

now extract the public key from the private key:

openssl rsa -in key.priv -outform PEM -pubout -out key.pub

and give a close look to the public key too

cat key.pub
-----END PUBLIC KEY-----

The Digital Signature Algorithm (DSA) is a Federal Information Processing Standard (FIPS) for digital signatures based on the mathematical concept of modular exponentiation and the discrete logarithm problem. Despite it being patented, NIST has made it available worldwide royalty-free. Note that FIPS 186-5 discourages to use DSA to generate signatures, but permit its usage to verify already existent signatures

Let see how to generate and DSA key pair:let's generate a 2048 bit AES256 encrypted (-aes256 parameter) DSA key:

openssl dsaparam -genkey 2048 | openssl dsa -aes256 -out key.priv

you can give a close look to it as follows:

openssl dsa -in key.priv -noout -text

after typing the unlocking (decrypting) password, the output is as follows:

Private-Key: (2048 bit)

now extract the public key from the private key:

openssl dsa -in key.priv -outform PEM -pubout -out key.pub

and give a close look to the public key too – I cut it to keep it short

cat key.pub
-----END PUBLIC KEY-----
The strength of both RSA and DSA keys is provided by the key length (bitness): the more bit is the key, the more difficult it is to break. Take in account that chances to break contents protected by key increase as years go by, since computers become more and more powerful. For this reason it is wise to generate a new key after a few years, and keep current of security weaknesses that may arise..
You may be wondering when to use DSA or RSA keys: despite by the security perspective they can be considered equivalent when dealing with keys of equal length, DSA is faster than RSA for signature generation but is slower for validation and when encrypting, although it is faster when decrypting and.
Elliptic Curves (EC)

The Elliptic Curve Cryptography (ECC) is modern family of public-key cryptosystems based on the algebraic structures of the elliptic curves over finite fields and relies on the difficulty of the Elliptic Curve Discrete Logarithm Problem (ECDLP).

ECC provides a set of predefined curves, we can list the curves supported by the version of openssl we are using as follows:

openssl ecparam -list_curves

on my system the outcome is:

  secp384r1 : NIST/SECG curve over a 384 bit prime field
  secp521r1 : NIST/SECG curve over a 521 bit prime field
  prime256v1: X9.62/SECG curve over a 256 bit prime field
The strength of EC keys is provided by the curve used. Take in account that chances to break contents protected by key increase as years go by, since computers become more and more powerful. For this reason it is wise to generate a new key after a few years, and keep current of security weaknesses that may arise.

Generate an AES256 encrypted (-aes256 parameter) EC private key using secp384r1 curve:

openssl ecparam -name secp384r1 -genkey | openssl ec -out key.priv -aes256

note that we had to create a pipeline, issuing openssl command twice: the first creates the unencrypted key that is piped to the second one that encrypts it. You can give a close look to it as follows:

openssl ec -in key.priv -noout -text

after typing the unlocking (decrypting) password, the output is as follows:

Private-Key: (384 bit)
ASN1 OID: secp384r1

now extract the public key from the private key:

openssl ec -in key.priv -pubout -out key.pub

and have a close look to the public key too

cat key.pub 
-----END PUBLIC KEY-----
When using openssl command to “pretty print” the keys, did you notice how small the EC key is compared to RSA or DSA keys? This is one of the reasons the world is moving towards EC keys.


To foster the support of keys from as many devices as possible, a few standards for encoding and formatting have been defined. There are two different ways to encode private keys (along with X.509 certificates, if necessary):


The Privacy-Enhanced Mail (PEM), is the most commonly used encoding - and the default used by OpenSSL: it is a Base64 ASCII encoded text file containing one or more items separated by plain-text headers and footers (e.g. -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----). Besides the private key, a PEM file can contain one or more X.509 certificates and are suitable to store a list of certificates to be used as truststore or to store a Certificate Signing Request (CSR)- but this will be the topic of another post). Usually PEM files are named with the following extensions: .crt, .pem, .cer, and .key.


The Distinguished Encoding Rules (DER) is a binary encoding, less commonly used than PEM.


Besides encoding, there do exists several formats: the most commonly used for private keys are:


This is the traditional and default format used by OpenSSL: it has the following header and footer:

Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,9AA41915E12E28466900B2BC60801ACA

The type of the key is specified after the BEGIN keyword, for example RSA, DSA, ECC.


It is a format that provides a stronger encryption and is FIPS 140-2 compliant too:


you can convert an existing private key to pkcs#8 as follows:

openssl pkcs8 -topk8 -outform PEM -nocrypt -in key.priv -out key.pkcs8

Generating Keys using PGP/GPG

OpenPGP is a suite that relies on asymmetric keys: it can generate both RSA, DSA or even ECC keys (note that only recent versions support ECC). For the sake of completeness, let's have a go with it too: let's generate an OpenPGP master key along with a sub-key with encryption capability as follows:

gpg --expert --full-gen-key
A PGP master key is a key that is solely used to sign the sub-keys (your own and the one of other's parties during key signing parties). Your reputation in the web of trust is tightly bound to this key, so you should do your best to keep it as secure as possible. The advice is to store them onto two different offline devices, such as pen-drives, stored in different locations. We'll go more on this in the post dedicated to PGP I'm going to write.

the above command starts an interactive tool that gathers the required information to generate the keys - Note that I cut some of the messages to keep it short and improve the overall readability:

gpg (GnuPG) 2.2.9; Copyright (C) 2018 Free Software Foundation, Inc.
gpg: directory '/home/vagrant/.gnupg' created
gpg: keybox '/home/vagrant/.gnupg/pubring.kbx' created
Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
   (9) ECC and ECC
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (13) Existing key
Your selection? 

enter 1 so to generate both master key and subkey as RSA keys.

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 

this is the key length (sometimes called bitness) of the master key: the longer a key is, the more time is required to brute-force it. Mind also that it also may require more time to gather enough entropy to generate it - this can be an issue on virtualized hosts with a poor support to entropy devices.

Enter 4096.

Requested keysize is 4096 bits
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want for the subkey? (2048) 

this time we set the key length of the sub-key: enter 4096 again

Requested keysize is 4096 bits
Requested keysize is 4096 bits
Please specify how long the key should be valid.
         0 = key does not expire
Key is valid for? (0) 

this is the desired lifetime of the keys: once reached the key expires and it is needed to generate them again. It's up to you to decide this value. However it is a best practice avoiding keys that lasts more than 10 years.

Enter 3650

Key expires at Thu May 16 17:43:25 2030 UTC
Is this correct? (y/N) 

here you can confirm or cancel before going on and actually generating the key: enter y

Now you should enter the metadata that are bundled along with the key: in the end you get the following output:

GnuPG needs to construct a user ID to identify your key.

Real name: Marco Antonio Carcano
Email address: marco@grimoire.carcano.ch
Comment: Marco's key
You selected this USER-ID:
    "Marco Antonio Carcano (Marco's key) <marco@grimoire.carcano.ch>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?

Enter O.

The tool now asks for a password to encrypt the keys:

│ Please enter the passphrase to                       │
│ protect your new key                                 │
│                                                      │
│ Passphrase: ________________________________________ │
│                                                      │
│                                                      │
└─                                                     ┘

Wait until the generation of the keys completes: in the end it should look like as follows:

gpg: /home/macarcano/.gnupg/trustdb.gpg: trustdb created
gpg: key EAEF77DC65FCAACC marked as ultimately trusted
gpg: directory '/home/macarcano/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/macarcano/.gnupg/openpgp-revocs.d/96544ECF4FEE48C70C0032AEEAEF77DC65FCAACC.rev'
public and secret key created and signed.

pub   rsa4096 2021-05-15 [SC] [expires: 2031-05-13]
uid                      Marco Antonio Carcano (Marco's key) <marco@grimoire.carcano.ch>
sub   rsa4096 2021-05-15 [E] [expires: 2031-05-13]/code>
PGP calls a key a bundle that is made of the private key(s) along with the metadata, ... this makes it sounds a little bit more like a certificate rather than a key.

The next thing to do is to export the public key so to share it with other parties: we can do this as follows:

gpg --armor --export marco@grimoire.carcano.ch > marco@grimoire.carcano.ch.pub

We can export the private key too if you need it:

gpg --export-secret-keys --armor marco@grimoire.carcano.ch > marco@grimoire.carcano.ch.priv

It asks for the decrypting password:

│ Please enter the passphrase to export the OpenPGP secret key:	     │
│ "Marco Antonio Carcano (Marco's key) <marco@grimoire.carcano.ch>"  │
│ 4096-bit RSA key, ID EAEF77DC65FCAACC,                             │
│ created 2021-05-15.                                                │
│                                                                    │
│                                                                    │
│ Passphrase: ______________________________________________________ │
│                                                                    │
│                                                     	             │
└─                                                                   ┘

let's have a look to the exported file - the output is of course cut:

cat marco@grimoire.carcano.ch.priv 


As you can see the file starts with a heading "-----BEGIN PGP PRIVATE KEY BLOCK-----" and ends with a trailing "-----END PGP PRIVATE KEY BLOCK-----" marker.

You should backup the exported private keys and store them offline in a secure location. To reduce risks, the best practice is to remove the primary key from the keyring and use only the sub-key to operate with PGP: if needed, you can import it again in the keyring as follows - in this example you should first remove ~./gnupg directory to simulate an uninitliaized PGP environment:

gpg --import cat marco@grimoire.carcano.ch.priv 

As you can see the exported key is encrypted and asks you for the decryption password:

│ Please enter the passphrase to import the OpenPGP secret key:	     │
│ "Marco Antonio Carcano (Marco's key) <marco@grimoire.carcano.ch>"  │
│ 4096-bit RSA key, ID EAEF77DC65FCAACC,                             │
│ created 2021-05-15.                                                │
│                                                                    │
│                                                                    │
│ Passphrase: ______________________________________________________ │
│                                                                    │
│                                                	             │
└─                                                                   ┘

an export the private key too if you need it:

gpg: directory '/home/macarcano/.gnupg' created
gpg: keybox '/home/macarcano/.gnupg/pubring.kbx' created
gpg: /home/macarcano/.gnupg/trustdb.gpg: trustdb created
gpg: key EAEF77DC65FCAACC: public key "Marco Antonio Carcano (Marco's key) <marco@grimoire.carcano.ch>" imported
gpg: key EAEF77DC65FCAACC/EAEF77DC65FCAACC: error sending to agent: No such file or directory
gpg: error building skey array: No such file or directory
gpg: error reading 'marco@grimoire.carcano.ch.priv': No such file or directory
gpg: import from 'marco@grimoire.carcano.ch.priv' failed: No such file or directory
gpg: Total number processed: 0
gpg: imported: 1
gpg: secret keys read: 1

The same command can be used also to import public keys of other users. Note that  it is not necessary to re-import your own public keys since they are derived from the private key.

If you want to read more on how to properly use GPG, you may find it useful reading A quick, easy yet comprehensive GPG tutorial.

Encrypting contents using public keys

Data is encrypted with the public key and decrypted by the private key. This encryption type relies on asymmetric key pairs:

  • public as the name suggests can be safely spread all over the world
  • private as the name suggests should never and ever be disclosed

Let’s say we want to encrypt a file called test.txt.

openssl rsautl -encrypt -inkey key.pub -pubin -in /etc/issue -out issue.dat

Let's try to decrypt the file using the private key (key.priv):

openssl rsautl -decrypt -inkey key.priv -in issue.dat -out issue.txt

Signing contents using our private key

It is the scrambling of data so that it appears without an understandable meaning: scrambled data are said to be hashed, whereas the original data are said to be plain-text. Hashing are one-way algorithms: once a message is hashed, there's no way (in a reasonable time) to get back the plain-text original message.

We can get a list of digest supported by openssl as follows:

openssl list --digest-commands

we can use digest to digitally sign a content as follows:

openssl dgst -sha256 -sign key.priv -out issue.sha256 /etc/issue

since the signature file is made of binary data, it is often convenient to convert it to base64 to improve its portability:

openssl enc -base64 -in issue.sha256 -out issue.sha256.base64

om my system, the contents of issue.sha256.base64 is as follows:


We can verify the signature as follows: convert the signature file back from base64 to binary:

openssl enc -base64 -d -in issue.sha256.base64 -out issue.sha256

perform the actual verification of the binary signature using the public key:

openssl dgst -sha256 -verify key.pub -signature issue.sha256 /etc/issue

if signature is valid, we should get:

Verified OK

If otherwise you get the following output

Verification Failure

it means that the /etc/issue file has been tampered.

Digital Certificates

One issue with asymmetric key crypto systems is the difficulty to ensure that the public key we are using actually belongs to the entity we think it should belong to. And here comes certificates into play: certificates are plain text contents digitally signed by a trusted entity: when dealing with X.509 certificates (the typical certificates used for example by websites) the trusted entity is the Certification Authority, whereas when working with OpenPGP certificates (that most of people simply calls OpenPGP public keys) the trusted entity is the private key of a trusted entity (We'll see this on a post dedicated to PGP and the web of trust).
To clarify the needs of it, think of a digital certificate as the digital version of a real life certificate. So what is a certificate, in real life?
It's a document that is trusted by who consider trustable the entity that signed it
Well, this is valid also for digital certificates..

Shamir's Secret Sharing

One of the problems of keys is how to protect them: of course they are encrypted on disk and so are password protected, but even if you configure things to interactively ask for the password to unlock the key at service start, you should blindly trust the members of your staff that will do this.
An alternative may be to require more people of the staff to enter a password, so that when at least a certain number of them have done it the key gets unlocked.
This can be achieved using Shamir's secret sharing: it consists of splitting the key into multiple parts, called shares, that are used to rebuild the original secret. The algorithm lets you define a threshold of keys you should provide to recreate the master key (for example you can generate 5 shares with a threshold of 3 shares: this means that three share holders can get-back the original key). There are several implementations of this algorithm, for example, when coding in python, you can install the library by using pip:

pip install shamir


Here it ends our cryptography quick guide: I hope you enjoyed it, and that you agree that is nicer having a little bit understanding about it rather than simply blindly run cryptographic suites commands.

Writing a post like this takes a lot of hours. I'm doing it for the only pleasure of sharing knowledge and thoughts, but all of this does not come for free: it is a time consuming volunteering task. This blog is not affiliated to anybody, does not show advertisements nor sells data of visitors. The only goal of this blog is to make ideas flow. So please, if you liked this post, spend a little of your time to share it on Linkedin or Twitter using the buttons below: seeing that posts are actually read is the only way I have to understand if I'm really sharing thoughts or if I'm just wasting time and I'd better give up.





12 thoughts on “Cryptography quick guide – understand symmetric and asymmetric cryptography and how to use it with OpenSSL

  1. gerald eggenberger says:

    Keep going writing such nice Posts. To write easy readable content which is easy to understand needs a deep understanding of the topic. Thanks for sharing your grimoire with us. 😀

    • Marco Antonio Carcano says:

      I’m pleased to see you liked the post and appreciate my grimoire, … this is exactly the reason I started with it: sharing thoughts and ideas. You are right, writing this kind of posts needs a deep understanding of the topic, and a lot of time rewriting the things until I feel I explained them in a way that, … can even be understood. So thank you for the feedback Gerald, it’s really appreciated.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>