qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ToxEncrypt Class Reference

Encapsulates the toxencrypsave API. Since key derivation is work intensive and to avoid storing plaintext passwords in memory, use a ToxEncrypt object and encrypt() or decrypt() when you have to encrypt or decrypt more than once with the same password. More...

#include <toxencrypt.h>

Collaboration diagram for ToxEncrypt:
Collaboration graph

Public Member Functions

 ~ToxEncrypt ()
 Frees the passKey before destruction. More...
 
 ToxEncrypt ()=delete
 
 ToxEncrypt (const ToxEncrypt &other)=delete
 
ToxEncryptoperator= (const ToxEncrypt &other)=delete
 
QByteArray encrypt (const QByteArray &plaintext) const
 Encrypts the plaintext with the stored key. More...
 
QByteArray decrypt (const QByteArray &ciphertext) const
 Decrypts data encrypted with this module, using the stored key. More...
 

Static Public Member Functions

static int getMinBytes ()
 Gets the minimum number of bytes needed for isEncrypted() More...
 
static bool isEncrypted (const QByteArray &ciphertext)
 Checks if the data was encrypted by this module. More...
 
static QByteArray encryptPass (const QString &password, const QByteArray &plaintext)
 Encrypts the plaintext with the given password. More...
 
static QByteArray decryptPass (const QString &password, const QByteArray &ciphertext)
 Decrypts data encrypted with this module. More...
 
static std::unique_ptr< ToxEncryptmakeToxEncrypt (const QString &password)
 Factory method for the ToxEncrypt object. More...
 
static std::unique_ptr< ToxEncryptmakeToxEncrypt (const QString &password, const QByteArray &toxSave)
 Factory method for the ToxEncrypt object. More...
 

Private Member Functions

 ToxEncrypt (Tox_Pass_Key *key)
 Constructs a ToxEncrypt object from a Tox_Pass_Key. More...
 

Private Attributes

Tox_Pass_Key * passKey = nullptr
 

Detailed Description

Encapsulates the toxencrypsave API. Since key derivation is work intensive and to avoid storing plaintext passwords in memory, use a ToxEncrypt object and encrypt() or decrypt() when you have to encrypt or decrypt more than once with the same password.

Definition at line 29 of file toxencrypt.h.

Constructor & Destructor Documentation

◆ ~ToxEncrypt()

ToxEncrypt::~ToxEncrypt ( )

Frees the passKey before destruction.

Definition at line 45 of file toxencrypt.cpp.

◆ ToxEncrypt() [1/3]

ToxEncrypt::ToxEncrypt ( )
delete

◆ ToxEncrypt() [2/3]

ToxEncrypt::ToxEncrypt ( const ToxEncrypt other)
delete

◆ ToxEncrypt() [3/3]

ToxEncrypt::ToxEncrypt ( Tox_Pass_Key *  key)
explicitprivate

Constructs a ToxEncrypt object from a Tox_Pass_Key.

Parameters
keyDerived key to use for encryption and decryption.

Definition at line 54 of file toxencrypt.cpp.

Member Function Documentation

◆ decrypt()

QByteArray ToxEncrypt::decrypt ( const QByteArray &  ciphertext) const

Decrypts data encrypted with this module, using the stored key.

Returns
The plaintext or an empty QByteArray on failure.
Parameters
ciphertextThe encrypted data.

Definition at line 245 of file toxencrypt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decryptPass()

QByteArray ToxEncrypt::decryptPass ( const QString &  password,
const QByteArray &  ciphertext 
)
static

Decrypts data encrypted with this module.

Returns
The plaintext or an empty QByteArray on failure.
Parameters
passwordThe password used to encrypt the data.
ciphertextThe encrypted data.

Definition at line 120 of file toxencrypt.cpp.

Here is the call graph for this function:

◆ encrypt()

QByteArray ToxEncrypt::encrypt ( const QByteArray &  plaintext) const

Encrypts the plaintext with the stored key.

Returns
Encrypted data or empty QByteArray on failure.
Parameters
plaintextThe data to encrypt.

Definition at line 218 of file toxencrypt.cpp.

Here is the caller graph for this function:

◆ encryptPass()

QByteArray ToxEncrypt::encryptPass ( const QString &  password,
const QByteArray &  plaintext 
)
static

Encrypts the plaintext with the given password.

Returns
Encrypted data or empty QByteArray on failure.
Parameters
passwordPassword to encrypt the data.
plaintextThe data to encrypt.

Definition at line 90 of file toxencrypt.cpp.

◆ getMinBytes()

int ToxEncrypt::getMinBytes ( )
static

Gets the minimum number of bytes needed for isEncrypted()

Returns
Minimum number of bytes needed to check if data was encrypted using this module.

Definition at line 64 of file toxencrypt.cpp.

◆ isEncrypted()

bool ToxEncrypt::isEncrypted ( const QByteArray &  ciphertext)
static

Checks if the data was encrypted by this module.

Parameters
ciphertextThe data to check.
Returns
True if the data was encrypted using this module, false otherwise.

Definition at line 74 of file toxencrypt.cpp.

Here is the caller graph for this function:

◆ makeToxEncrypt() [1/2]

std::unique_ptr< ToxEncrypt > ToxEncrypt::makeToxEncrypt ( const QString &  password)
static

Factory method for the ToxEncrypt object.

Parameters
passwordPassword to use for encryption.
Returns
A std::unique_ptr containing a ToxEncrypt object on success, or an or an empty std::unique_ptr on failure.

Derives a key from the password and a new random salt.

Definition at line 156 of file toxencrypt.cpp.

Here is the caller graph for this function:

◆ makeToxEncrypt() [2/2]

std::unique_ptr< ToxEncrypt > ToxEncrypt::makeToxEncrypt ( const QString &  password,
const QByteArray &  toxSave 
)
static

Factory method for the ToxEncrypt object.

Parameters
passwordPassword to use for encryption.
toxSaveThe data to read the salt for decryption from.
Returns
A std::unique_ptr containing a ToxEncrypt object on success, or an or an empty std::unique_ptr on failure.

Derives a key from the password and the salt read from toxSave.

Definition at line 182 of file toxencrypt.cpp.

Here is the call graph for this function:

◆ operator=()

ToxEncrypt& ToxEncrypt::operator= ( const ToxEncrypt other)
delete

Member Data Documentation

◆ passKey

Tox_Pass_Key* ToxEncrypt::passKey = nullptr
private

Definition at line 51 of file toxencrypt.h.


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