Cuberite
A lightweight, fast and extensible game server for Minecraft
CryptoKey.h
Go to the documentation of this file.
1 
2 // CryptoKey.h
3 
4 // Declares the cCryptoKey class representing a RSA public key in mbedTLS
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "CtrDrbgContext.h"
13 #include "mbedtls/pk.h"
14 
15 
16 
17 
18 
20 {
21  friend class cSslConfig;
22 
23 public:
25  cCryptoKey(void);
26 
28  cCryptoKey(const AString & a_PublicKeyData);
29 
32  cCryptoKey(const AString & a_PrivateKeyData, const AString & a_Password);
33 
34  ~cCryptoKey();
35 
39  int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength);
40 
44  int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength);
45 
49  int ParsePublic(const void * a_Data, size_t a_NumBytes);
50 
55  int ParsePrivate(const void * a_Data, size_t a_NumBytes, const AString & a_Password);
56 
58  bool IsValid(void) const;
59 
60 protected:
62  mbedtls_pk_context m_Pk;
63 
66 
67 
69  mbedtls_pk_context * GetInternal(void) { return &m_Pk; }
70 } ;
71 
72 typedef std::shared_ptr<cCryptoKey> cCryptoKeyPtr;
73 
74 
75 
76 
unsigned char Byte
Definition: Globals.h:161
std::shared_ptr< cCryptoKey > cCryptoKeyPtr
Definition: CryptoKey.h:72
std::string AString
Definition: StringUtils.h:11
int ParsePrivate(const void *a_Data, size_t a_NumBytes, const AString &a_Password)
Parses the specified data into a private key representation.
Definition: CryptoKey.cpp:118
mbedtls_pk_context * GetInternal(void)
Returns the internal context ptr.
Definition: CryptoKey.h:69
mbedtls_pk_context m_Pk
The mbedTLS representation of the key data.
Definition: CryptoKey.h:62
int Encrypt(const Byte *a_PlainData, size_t a_PlainLength, Byte *a_EncryptedData, size_t a_EncryptedMaxLength)
Encrypts the data using the stored public key Both a_EncryptedData and a_DecryptedData must be at lea...
Definition: CryptoKey.cpp:87
int ParsePublic(const void *a_Data, size_t a_NumBytes)
Parses the specified data into a public key representation.
Definition: CryptoKey.cpp:107
bool IsValid(void) const
Returns true if the contained key is valid.
Definition: CryptoKey.cpp:144
cCryptoKey(void)
Constructs an empty key instance.
Definition: CryptoKey.cpp:13
int Decrypt(const Byte *a_EncryptedData, size_t a_EncryptedLength, Byte *a_DecryptedData, size_t a_DecryptedMaxLength)
Decrypts the data using the stored public key Both a_EncryptedData and a_DecryptedData must be at lea...
Definition: CryptoKey.cpp:66
cCtrDrbgContext m_CtrDrbg
The random generator used in encryption and decryption.
Definition: CryptoKey.h:65