Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <CryptoKey.h>
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 |
Definition at line 19 of file CryptoKey.h.
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::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.
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 | ( | ) |
Definition at line 57 of file CryptoKey.cpp.
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.
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.
|
inlineprotected |
Returns the internal context ptr.
Only use in mbedTLS API calls.
Definition at line 69 of file CryptoKey.h.
bool cCryptoKey::IsValid | ( | void | ) | const |
Returns true if the contained key is valid.
Definition at line 144 of file CryptoKey.cpp.
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.
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.
|
friend |
Definition at line 21 of file CryptoKey.h.
|
protected |
The random generator used in encryption and decryption.
Definition at line 65 of file CryptoKey.h.
|
protected |
The mbedTLS representation of the key data.
Definition at line 62 of file CryptoKey.h.