Cuberite
A lightweight, fast and extensible game server for Minecraft
RsaPrivateKey.h
Go to the documentation of this file.
1 
2 // RsaPrivateKey.h
3 
4 // Declares the cRsaPrivateKey class representing a private key for RSA operations.
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "CtrDrbgContext.h"
13 #include "mbedtls/rsa.h"
14 
15 
16 
17 
18 
21 {
22  friend class cSslContext;
23 
24 public:
26  cRsaPrivateKey(void);
27 
29  cRsaPrivateKey(const cRsaPrivateKey & a_Other);
30 
32 
35  bool Generate(unsigned a_KeySizeBits = 1024);
36 
38  AString GetPubKeyDER(void);
39 
43  int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength);
44 
48  int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength);
49 
50 protected:
52  mbedtls_rsa_context m_Rsa;
53 
56 
57 
59  mbedtls_rsa_context * GetInternal(void) { return &m_Rsa; }
60 } ;
61 
62 typedef std::shared_ptr<cRsaPrivateKey> cRsaPrivateKeyPtr;
63 
64 
65 
66 
67 
mbedtls_rsa_context m_Rsa
The mbedTLS key context.
Definition: RsaPrivateKey.h:52
int Decrypt(const Byte *a_EncryptedData, size_t a_EncryptedLength, Byte *a_DecryptedData, size_t a_DecryptedMaxLength)
Decrypts the data using RSAES-PKCS#1 algorithm.
AString GetPubKeyDER(void)
Returns the public key part encoded in ASN1 DER encoding.
int Encrypt(const Byte *a_PlainData, size_t a_PlainLength, Byte *a_EncryptedData, size_t a_EncryptedMaxLength)
Encrypts the data using RSAES-PKCS#1 algorithm.
cRsaPrivateKey(void)
Creates a new empty object, the key is not assigned.
mbedtls_rsa_context * GetInternal(void)
Returns the internal context ptr.
Definition: RsaPrivateKey.h:59
std::shared_ptr< cRsaPrivateKey > cRsaPrivateKeyPtr
Definition: RsaPrivateKey.h:62
friend class cSslContext
Definition: RsaPrivateKey.h:22
cCtrDrbgContext m_CtrDrbg
The random generator used for generating the key and encryption / decryption.
Definition: RsaPrivateKey.h:55
std::string AString
Definition: StringUtils.h:13
Encapsulates an RSA private key used in PKI cryptography.
Definition: RsaPrivateKey.h:20
unsigned char Byte
Definition: Globals.h:117
bool Generate(unsigned a_KeySizeBits=1024)
Generates a new key within this object, with the specified size in bits.