Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
cCryptoKey Class Reference

#include <CryptoKey.h>

Collaboration diagram for cCryptoKey:
Collaboration graph
[legend]

Public Member Functions

 cCryptoKey (const AString &a_PrivateKeyData, const AString &a_Password)
 Constructs the private key out of the DER- or PEM-encoded privkey data, with the specified password. More...
 
 cCryptoKey (const AString &a_PublicKeyData)
 Constructs the public key out of the DER- or PEM-encoded pubkey data. More...
 
 cCryptoKey (void)
 Constructs an empty key instance. More...
 
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 least <KeySizeBytes> bytes large. More...
 
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 least <KeySizeBytes> bytes large. More...
 
bool IsValid (void) const
 Returns true if the contained key is valid. More...
 
int ParsePrivate (const void *a_Data, size_t a_NumBytes, const AString &a_Password)
 Parses the specified data into a private key representation. More...
 
int ParsePublic (const void *a_Data, size_t a_NumBytes)
 Parses the specified data into a public key representation. More...
 
 ~cCryptoKey ()
 

Protected Member Functions

mbedtls_pk_context * GetInternal (void)
 Returns the internal context ptr. More...
 

Protected Attributes

cCtrDrbgContext m_CtrDrbg
 The random generator used in encryption and decryption. More...
 
mbedtls_pk_context m_Pk
 The mbedTLS representation of the key data. More...
 

Friends

class cSslConfig
 

Detailed Description

Definition at line 19 of file CryptoKey.h.

Constructor & Destructor Documentation

◆ cCryptoKey() [1/3]

cCryptoKey::cCryptoKey ( void  )

Constructs an empty key instance.

Before use, it needs to be filled by ParsePublic() or ParsePrivate()

Definition at line 13 of file CryptoKey.cpp.

◆ cCryptoKey() [2/3]

cCryptoKey::cCryptoKey ( const AString a_PublicKeyData)

Constructs the public key out of the DER- or PEM-encoded pubkey data.

Definition at line 23 of file CryptoKey.cpp.

◆ cCryptoKey() [3/3]

cCryptoKey::cCryptoKey ( const AString a_PrivateKeyData,
const AString a_Password 
)

Constructs the private key out of the DER- or PEM-encoded privkey data, with the specified password.

If a_Password is empty, no password is assumed.

Definition at line 40 of file CryptoKey.cpp.

◆ ~cCryptoKey()

cCryptoKey::~cCryptoKey ( )

Definition at line 57 of file CryptoKey.cpp.

Member Function Documentation

◆ Decrypt()

int cCryptoKey::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 least <KeySizeBytes> bytes large.

Returns the number of bytes decrypted, or negative number for error.

Definition at line 66 of file CryptoKey.cpp.

◆ Encrypt()

int cCryptoKey::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 least <KeySizeBytes> bytes large.

Returns the number of bytes decrypted, or negative number for error.

Definition at line 87 of file CryptoKey.cpp.

◆ GetInternal()

mbedtls_pk_context* cCryptoKey::GetInternal ( void  )
inlineprotected

Returns the internal context ptr.

Only use in mbedTLS API calls.

Definition at line 69 of file CryptoKey.h.

◆ IsValid()

bool cCryptoKey::IsValid ( void  ) const

Returns true if the contained key is valid.

Definition at line 144 of file CryptoKey.cpp.

◆ ParsePrivate()

int cCryptoKey::ParsePrivate ( const void *  a_Data,
size_t  a_NumBytes,
const AString a_Password 
)

Parses the specified data into a private key representation.

If a_Password is empty, no password is assumed. The key can be DER- or PEM-encoded. Returns 0 on success, mbedTLS error code on failure.

Definition at line 118 of file CryptoKey.cpp.

◆ ParsePublic()

int cCryptoKey::ParsePublic ( const void *  a_Data,
size_t  a_NumBytes 
)

Parses the specified data into a public key representation.

The key can be DER- or PEM-encoded. Returns 0 on success, mbedTLS error code on failure.

Definition at line 107 of file CryptoKey.cpp.

Friends And Related Function Documentation

◆ cSslConfig

friend class cSslConfig
friend

Definition at line 21 of file CryptoKey.h.

Member Data Documentation

◆ m_CtrDrbg

cCtrDrbgContext cCryptoKey::m_CtrDrbg
protected

The random generator used in encryption and decryption.

Definition at line 65 of file CryptoKey.h.

◆ m_Pk

mbedtls_pk_context cCryptoKey::m_Pk
protected

The mbedTLS representation of the key data.

Definition at line 62 of file CryptoKey.h.


The documentation for this class was generated from the following files: