PcapPlusPlus  Next
pcpp::PemCodec Class Reference

A utility class for encoding and decoding data in Privacy-Enhanced Mail (PEM) format. More...

#include <PemCodec.h>

Static Public Member Functions

static std::string encode (const std::vector< uint8_t > &data, const std::string &label)
 
static std::vector< uint8_t > decode (const std::string &pemData, const std::string &expectedLabel="")
 

Detailed Description

A utility class for encoding and decoding data in Privacy-Enhanced Mail (PEM) format.

The PemCodec class provides static methods to convert between binary data and PEM format, which is commonly used for cryptographic keys, certificates, and other security-related data. The PEM format uses base64 encoding with header and footer lines.

Member Function Documentation

◆ decode()

static std::vector<uint8_t> pcpp::PemCodec::decode ( const std::string &  pemData,
const std::string &  expectedLabel = "" 
)
static

Decodes PEM-encoded data back to its binary form

Parameters
[in]pemDataThe PEM-encoded string to decode
[in]expectedLabelOptional expected label that should be in the PEM header/footer. If provided and doesn't match, an exception will be thrown
Returns
A vector containing the decoded binary data
Exceptions
std::invalid_argumentif the input is not valid PEM format, if the label doesn't match or if base64 decoding fails

◆ encode()

static std::string pcpp::PemCodec::encode ( const std::vector< uint8_t > &  data,
const std::string &  label 
)
static

Encodes binary data into PEM format with the specified label

Parameters
[in]dataThe binary data to be encoded
[in]labelThe label to be used in the PEM header/footer (e.g., "CERTIFICATE", "PRIVATE KEY")
Returns
A string containing the PEM-encoded data with appropriate headers and line breaks
Exceptions
std::invalid_argumentif the input data is empty or the label is empty