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 
39 
43  int Decrypt(ContiguousByteBufferView a_EncryptedData, Byte * a_DecryptedData, size_t a_DecryptedMaxLength);
44 
45 protected:
47  mbedtls_rsa_context m_Rsa;
48 
51 
52 
54  mbedtls_rsa_context * GetInternal(void) { return &m_Rsa; }
55 } ;
56 
57 typedef std::shared_ptr<cRsaPrivateKey> cRsaPrivateKeyPtr;
58 
59 
60 
61 
62 
std::basic_string_view< std::byte > ContiguousByteBufferView
Definition: Globals.h:376
std::basic_string< std::byte > ContiguousByteBuffer
Definition: Globals.h:375
unsigned char Byte
Definition: Globals.h:161
std::shared_ptr< cRsaPrivateKey > cRsaPrivateKeyPtr
Definition: RsaPrivateKey.h:57
Encapsulates an RSA private key used in PKI cryptography.
Definition: RsaPrivateKey.h:21
friend class cSslContext
Definition: RsaPrivateKey.h:22
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:54
mbedtls_rsa_context m_Rsa
The mbedTLS key context.
Definition: RsaPrivateKey.h:47
cCtrDrbgContext m_CtrDrbg
The random generator used for generating the key and encryption / decryption.
Definition: RsaPrivateKey.h:50
int Decrypt(ContiguousByteBufferView a_EncryptedData, Byte *a_DecryptedData, size_t a_DecryptedMaxLength)
Decrypts the data using RSAES-PKCS#1 algorithm.
ContiguousByteBuffer GetPubKeyDER(void)
Returns the public key part encoded in ASN1 DER encoding.
bool Generate(unsigned a_KeySizeBits=1024)
Generates a new key within this object, with the specified size in bits.