CppSecurity  1.1.1.0
C++ Security Library
Public Member Functions | Static Public Member Functions | List of all members
CppSecurity::Cipher Class Reference

Cipher. More...

#include <cipher.h>

Public Member Functions

 Cipher (CipherAlgorithm algorithm=CipherAlgorithm::AES256, size_t iterations=1000)
 Initialize cipher with required algorithm. More...
 
 Cipher (std::string_view secret, CipherAlgorithm algorithm=CipherAlgorithm::AES256, size_t iterations=1000)
 Initialize cipher with the given secret key and required algorithm. More...
 
 Cipher (std::string_view secret, std::string_view salt, CipherAlgorithm algorithm=CipherAlgorithm::AES256, size_t iterations=1000)
 Initialize cipher with the given secret key, unique salt and required algorithm. More...
 
 Cipher (const Cipher &)=delete
 
 Cipher (Cipher &&)=default
 
 ~Cipher ()=default
 
Cipheroperator= (const Cipher &)=delete
 
Cipheroperator= (Cipher &&)=default
 
CipherAlgorithm algorithm () const noexcept
 Get the cipher algorithm. More...
 
const std::string & name () const noexcept
 Get the cipher algorithm name. More...
 
size_t iterations () const noexcept
 Get the count of key hashing iterations. More...
 
void Initialize (std::string_view secret)
 Initialize the cipher with the given secret key. More...
 
void Initialize (std::string_view secret, std::string_view salt)
 Initialize the cipher with the given secret key and unique salt. More...
 
std::string Encrypt (std::string_view str)
 Encrypt the given string. More...
 
std::string Decrypt (std::string_view str)
 Decrypt the given string. More...
 

Static Public Member Functions

static std::string GenerateSalt ()
 Generate the unique secret salt. More...
 

Detailed Description

Cipher.

Cipher allows to perform symmetric encode & decode data using a provided secret key and optional salt.

https://en.wikipedia.org/wiki/Symmetric-key_algorithm

Thread-safe.

Examples
cipher_decrypt.cpp, and cipher_encrypt.cpp.

Definition at line 43 of file cipher.h.

Constructor & Destructor Documentation

◆ Cipher() [1/5]

CppSecurity::Cipher::Cipher ( CipherAlgorithm  algorithm = CipherAlgorithm::AES256,
size_t  iterations = 1000 
)

Initialize cipher with required algorithm.

Parameters
algorithm- Cipher algorithm (default is CipherAlgorithm::AES256)
iterations- Count key hashing iterations (default is 1000)

Definition at line 17 of file cipher.cpp.

◆ Cipher() [2/5]

CppSecurity::Cipher::Cipher ( std::string_view  secret,
CipherAlgorithm  algorithm = CipherAlgorithm::AES256,
size_t  iterations = 1000 
)
inline

Initialize cipher with the given secret key and required algorithm.

Parameters
secret- Secret key
algorithm- Cipher algorithm (default is CipherAlgorithm::AES256)
iterations- Count key hashing iterations (default is 1000)

Definition at line 58 of file cipher.h.

◆ Cipher() [3/5]

CppSecurity::Cipher::Cipher ( std::string_view  secret,
std::string_view  salt,
CipherAlgorithm  algorithm = CipherAlgorithm::AES256,
size_t  iterations = 1000 
)
inline

Initialize cipher with the given secret key, unique salt and required algorithm.

Parameters
secret- Secret key
salt- Unique secret salt
algorithm- Cipher algorithm (default is CipherAlgorithm::AES256)
iterations- Count key hashing iterations (default is 1000)

Definition at line 66 of file cipher.h.

◆ Cipher() [4/5]

CppSecurity::Cipher::Cipher ( const Cipher )
delete

◆ Cipher() [5/5]

CppSecurity::Cipher::Cipher ( Cipher &&  )
default

◆ ~Cipher()

CppSecurity::Cipher::~Cipher ( )
default

Member Function Documentation

◆ algorithm()

CipherAlgorithm CppSecurity::Cipher::algorithm ( ) const
inlinenoexcept

Get the cipher algorithm.

Definition at line 75 of file cipher.h.

◆ Decrypt()

std::string CppSecurity::Cipher::Decrypt ( std::string_view  str)

Decrypt the given string.

Parameters
str- String to decrypt
Returns
Decrypted string
Examples
cipher_decrypt.cpp.

Definition at line 140 of file cipher.cpp.

◆ Encrypt()

std::string CppSecurity::Cipher::Encrypt ( std::string_view  str)

Encrypt the given string.

Parameters
str- String to encrypt
Returns
Encrypted string
Examples
cipher_encrypt.cpp.

Definition at line 117 of file cipher.cpp.

◆ GenerateSalt()

std::string CppSecurity::Cipher::GenerateSalt ( )
static

Generate the unique secret salt.

Returns
Unique secret salt

Definition at line 79 of file cipher.cpp.

◆ Initialize() [1/2]

void CppSecurity::Cipher::Initialize ( std::string_view  secret)

Initialize the cipher with the given secret key.

Parameters
secret- Secret key
Examples
cipher_decrypt.cpp, and cipher_encrypt.cpp.

Definition at line 86 of file cipher.cpp.

◆ Initialize() [2/2]

void CppSecurity::Cipher::Initialize ( std::string_view  secret,
std::string_view  salt 
)

Initialize the cipher with the given secret key and unique salt.

Parameters
secret- Secret key
salt- Unique secret salt

Definition at line 94 of file cipher.cpp.

◆ iterations()

size_t CppSecurity::Cipher::iterations ( ) const
inlinenoexcept

Get the count of key hashing iterations.

Examples
cipher_decrypt.cpp, and cipher_encrypt.cpp.

Definition at line 79 of file cipher.h.

◆ name()

const std::string& CppSecurity::Cipher::name ( ) const
inlinenoexcept

Get the cipher algorithm name.

Examples
cipher_decrypt.cpp, and cipher_encrypt.cpp.

Definition at line 77 of file cipher.h.

◆ operator=() [1/2]

Cipher& CppSecurity::Cipher::operator= ( Cipher &&  )
default

◆ operator=() [2/2]

Cipher& CppSecurity::Cipher::operator= ( const Cipher )
delete

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