PLCnext API Documentation  22.9.0.33
KeyPair.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
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 
15 namespace Arp { namespace System { namespace Commons { namespace Security
16 {
17 
18 using namespace Arp::System::Commons::Security::Internal;
19 
21 class KeyPair : private Loggable<KeyPair>
22 {
23 public: // typedefs
24 
25 public: // construction/destruction
29  KeyPair(const KeyPair& arg) = delete;
31  KeyPair& operator=(const KeyPair& arg) = delete;
33  virtual ~KeyPair(void);
34 
35 
36 public: // operators
37 
38 
39 public: // static operations
40 
41 
42 public: // setter/getter operations
45  EVP_PKEY* GetPkey();
46 
47 public: // 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 
75 protected: // fields
76  OpenSslEVP_PKEY opensslkey;
77  KeyPairType keyType;
78 private: // static methods
79 
80 
81 private: // methods
82  void ReadKeyType(void);
83 
84 private: // fields
85 
86 
87 
88 private: // static fields
89 
90 };
91 
93 // inline methods of class CertificateStore
94 inline EVP_PKEY* KeyPair::GetPkey()
95 {
96  return this->opensslkey;
97 }
98 
99 inline 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
std::vector< byte > GetPublicKey()
summary>Returns the type of this key pair
KeyPair & operator=(const KeyPair &arg)=delete
Assignment operator.
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)
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.
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