PLCnext API Documentation 25.0.2.69
KeyPair.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Commons/Logging.h"
9#include "Arp/System/Commons/Security/KeyPairType.hpp"
10#include "Arp/System/Commons/Security/Internal/OpenSslBio.hpp"
11#include "Arp/System/Commons/Security/Internal/OpenSslEVP_PKEY.hpp"
12#include <vector>
13#include <openssl/x509.h>
14
15namespace Arp { namespace System { namespace Commons { namespace Security
16{
17
18using namespace Arp::System::Commons::Security::Internal;
19
21class KeyPair : private Loggable<KeyPair>
22{
23public: // construction/destruction
24 KeyPair();
26 KeyPair(const KeyPair& arg) = delete;
28 KeyPair& operator=(const KeyPair& arg) = delete;
29 virtual ~KeyPair(void);
30
31public: // setter/getter operations
32 EVP_PKEY* GetPkey();
33
34public: // operations
35 virtual void LoadFromFile(const String& filename);
36 void LoadFromMemory(const std::vector<byte>& data);
37 void InitSslContext(SSL_CTX* pSslCtx)const;
38 std::vector<byte> GetPublicKey();
39 KeyPairType GetKeyType();
40 void WriteToFile(const String& filename);
41 void GenerateKeyPair(KeyPairType type);
42
43protected: // fields
44 OpenSslEVP_PKEY opensslkey;
45 KeyPairType keyType;
46
47private: // methods
48 void ReadKeyType(void);
49
50};
51
52}}}} // end of namespace Arp::System::Commons::Security
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Derive from this class to inherit logging functionality.
Definition: Loggable.hxx:28
class which represents a asymmetric key pair
Definition: KeyPair.hpp:22
void InitSslContext(SSL_CTX *pSslCtx) const
Initializes a OpenSSL SSL_CTX structure ith this KeyPair
Definition: KeyPair.cpp:60
KeyPair(const KeyPair &arg)=delete
Copy constructor.
virtual ~KeyPair(void)
Destructs this instance and frees all resources.
Definition: KeyPair.cpp:36
EVP_PKEY * GetPkey()
returns a pointer to the OpenSSL EVP_PKEY* structure initialized with this KeyPair
Definition: KeyPair.cpp:163
virtual void LoadFromFile(const String &filename)
Loads the KeyPair from a PEM encoded file filename
Definition: KeyPair.cpp:44
void GenerateKeyPair(KeyPairType type)
Generates a new key pair and replaced the current key pair with the generated
Definition: KeyPair.cpp:99
KeyPairType GetKeyType()
Returns the type of this key pair
Definition: KeyPair.cpp:169
void WriteToFile(const String &filename)
saves this KeyPair to a file in PEM format (the private key is not encrypted!)
Definition: KeyPair.cpp:92
std::vector< byte > GetPublicKey()
Returns the public key portion of this key pair (PEM format)
Definition: KeyPair.cpp:70
KeyPair()
Constructs an KeyPair
Definition: KeyPair.cpp:29
KeyPair & operator=(const KeyPair &arg)=delete
Assignment operator.
void LoadFromMemory(const std::vector< byte > &data)
Loads the KeyPair from memory (PEM encoded)
Definition: KeyPair.cpp:52
Root namespace for the PLCnext API