PLCnext API Documentation 23.6.0.37
KeyPair.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
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: // typedefs
24
25public: // construction/destruction
29 KeyPair(const KeyPair& arg) = delete;
31 KeyPair& operator=(const KeyPair& arg) = delete;
33 virtual ~KeyPair(void);
34
35
36public: // operators
37
38
39public: // static operations
40
41
42public: // setter/getter operations
45 EVP_PKEY* GetPkey();
46
47public: // operations
50 virtual void LoadFromFile(const String& filename);
51
54 void LoadFromMemory(const std::vector<byte>& data);
55
58 void InitSslContext(SSL_CTX* pSslCtx)const;
59
62 std::vector<byte> GetPublicKey();
63
65 KeyPairType GetKeyType();
66
68 void WriteToFile(const String& filename);
69
72 void GenerateKeyPair(KeyPairType type);
73
74
75protected: // fields
76 OpenSslEVP_PKEY opensslkey;
77 KeyPairType keyType;
78private: // static methods
79
80
81private: // methods
82 void ReadKeyType(void);
83
84private: // fields
85
86
87
88private: // static fields
89
90};
91
93// inline methods of class CertificateStore
94inline EVP_PKEY* KeyPair::GetPkey()
95{
96 return this->opensslkey;
97}
98
99inline KeyPairType KeyPair::GetKeyType()
100{
101 return this->keyType;
102}
103}}}} // end of namespace Arp::System::Commons::Security
class which represents a asymmetric key pair
Definition: KeyPair.hpp:22
void InitSslContext(SSL_CTX *pSslCtx) const
KeyPair(const KeyPair &arg)=delete
Copy constructor.
EVP_PKEY * GetPkey()
returns a pointer to the OpenSSL EVP_PKEY* structure initialized with this KeyPair
Definition: KeyPair.hpp:94
KeyPairType GetKeyType()
summary>saves this KeyPair to a file in PEM format (the private key is not encrypted!...
Definition: KeyPair.hpp:99
void WriteToFile(const String &filename)
std::vector< byte > GetPublicKey()
summary>Returns the type of this key pair
virtual void LoadFromFile(const String &filename)
Loads the KeyPair from a PEM encoded file filename
virtual ~KeyPair(void)
Destructs this instance and frees all resources.
KeyPair & operator=(const KeyPair &arg)=delete
Assignment operator.
void LoadFromMemory(const std::vector< byte > &data)
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API