Explaining the Difference between PGP and PEM File Formats

The aim of this page📝 is to explain the difference between PEM and PGP formats based on the particular example of a PEM certificate and a PGP message.

Pavol Kutaj
2 min readOct 31, 2023
  • PEM (Privacy-Enhanced Mail) and PGP (Pretty Good Privacy) are both formats that deal with cryptographic data.
  • They both use “BEGIN” and “END” markers to denote the start and end of the data.
  • The data between these markers is base64-encoded, which is a method of representing binary data in an ASCII string format.
  • However, they are used for different purposes and have different structures.
  • PEM is often used to send or store cryptographic keys, certificates, or other data.
  • PGP is used for signing, encrypting, and decrypting texts, emails, files, directories, and whole disk partitions.
  • The tool you use to decode a PEM or PGP message depends on the type of data it contains.
  • For example, if the PEM message contains a certificate, you can use OpenSSL’s x509 tool to decode it.
  • Of, I am using Kleopatra PGP to decrypt the secure communication containing passwords — of course with the necessary keys
  • If it contains a private key, you can use OpenSSL’s rsa or ec tool, depending on whether it's an RSA or EC key.
  • Here are the obfuscated and shortened examples of PGP and PEM formats

PGP Format Example

-----BEGIN PGP MESSAGE-----
wcFMA61qEhw/yzcWAQ//d3EWYRBoPN/SHeS/Z70rFaiaQkSqMmwXeLXhdSNh
EEck9+BqUPFAtXMAbg+sfISHH0I3zI9wSdevN21SDqkd4pwKfNoQDZAFqRZ9
/dJJPABeNS5DH4ybMjVqmMdA+AvkCztlWWcbsTzs3P0D8Q0t59k5aleqLKVG
...
=KOnh
-----END PGP MESSAGE-----

PEM Format Example

-----BEGIN CERTIFICATE-----
MIIEQjCCAqqgAwIBAgIUFK72AQlZN//HTWKtc7t9iuu9c+QwDQYJKoZIhvcNAQEM
BQAwOjE4MDYGA1UEAwwvYjBkMmY1OWMtMWE5ZC00YTIwLTlkZjgtZWU3MjQxMjgz
MDNjIFByb2plY3QgQ0EwHhcNMjIwNTE5MTQxODUwWhcNMjQwODE2MTQxODUwWjBB
...
-----END CERTIFICATE-----

In both examples, I’ve replaced some of the content with ... to keep them anonymous and short. These are just small portions of what the full PGP message or PEM certificate would look like. The full versions would contain much more data. Remember, the actual content between the "BEGIN" and "END" markers is base64-encoded binary data.

LINKS

--

--

No responses yet