AES128ESP32 Library
Loading...
Searching...
No Matches
crypto Class Reference

#include <crypto.h>

Public Member Functions

 crypto ()
bool begin ()
void setkeyaccess (pass2Key *keyholder)
void setkeyaccess (pass2Key &keyholder)
unsigned char * getIVbytes (size_t &IVsize)
void setIVbytes (unsigned char *bytes, size_t byteslength)
void clearIV ()
String Decrypt (unsigned char *bytes, size_t len)
unsigned char * Encrypt (String datatoEncrypt, size_t &outputsize)

Detailed Description

For decryption to be successfull the following need to be identical to the values used for the encryption. the key data the iv data For encryption to be successful the following need to exist. the key data optionally the iv data. If the iv data does not exist a new iv will be generated.

To setup the key data call the setkeyaccess()

responsabilities create a pass2Key object create a masterkey (with makekey() ) and persist the data (with getmasterkey() ) - you don't want to loose the master key once it has been created. the masterkey cannot encrypt or decrypt data because of security added to the data. it can only generate newkey data. if you already have the masterkey available use the function setmasterkey() generate a newkey from the plain text password. derivekeyfromtext(). you cannot save the newkey data, it always needs to be generated.

create a crpto object set the keys to the crypto object using setkeyaccess() * if you change the pass2Key object you need to update the cryto object again now you can encrypt but not decrypt. if you have a IV already you can call the setIVbytes() after you set the IV you can decrypt. if you do not have a IV when you call Encrypt() it will generate a new IV, use getIVbytes() so you can save the IV data. if the pass2Key goes out of scope the cypto class will not function. it will probably fail/crash.

what to know masterkey: can only generate new keys. you can persist the masterkey newkey: can only encrypt or decrypt data. you cannot persist the newkey. it is considered secret IV: is not considered secret. you can persist the IV. password: is considered secret, it must never be saved.

Definition at line 56 of file crypto.h.

Constructor & Destructor Documentation

◆ crypto()

crypto::crypto ( )
inline

Definition at line 69 of file crypto.h.

Member Function Documentation

◆ begin()

bool crypto::begin ( )
inline

return false if it fails to initialize the crypto engine.

Definition at line 71 of file crypto.h.

◆ clearIV()

void crypto::clearIV ( )
inline

clear the IV bytes, you can either generate a new IV during the Encryption function or set a previously existing IV with setIVBytes

Definition at line 122 of file crypto.h.

◆ Decrypt()

String crypto::Decrypt ( unsigned char * bytes,
size_t len )
inline

encrypt the string and return the encrpted bytes, the outputsize if the number of bytes returned. NOTE: it is critical to free the returned bytes example crypto cry; if (!cry.begin()) while(true) ; // oops it failed to initial the object cry.setkeyaccess(&k); // k is the pass2Key object size_t numOfbytes=0; // number of bytes in the allocated memory unsigned char* encoded=cry.Encrypt("1234567890abcdefG",numOfbytes); String rtn = cry.Decrypt(encoded, numOfbytes); free(encoded);

Definition at line 182 of file crypto.h.

◆ Encrypt()

unsigned char * crypto::Encrypt ( String datatoEncrypt,
size_t & outputsize )
inline

Definition at line 218 of file crypto.h.

◆ getIVbytes()

unsigned char * crypto::getIVbytes ( size_t & IVsize)
inline

return the IV bytes, set the IVsize to the memory buffer size. If the user has not performed an encrypt operation the IV will not have been generated and will return 0 bytes. Without an IV it will not be possible to decrypt data, so the user must supply the IV data.

Definition at line 103 of file crypto.h.

◆ setIVbytes()

void crypto::setIVbytes ( unsigned char * bytes,
size_t byteslength )
inline

set the initialisation vector, this must be done before decryption can happen. This can also happen before encryption if you want to use a known IV. Once the IV bytes are set the encryption function will not generate a new IV. If you want to clear the IV bytes so a new IV is generated, use the clearIV() function.

Definition at line 113 of file crypto.h.

◆ setkeyaccess() [1/2]

void crypto::setkeyaccess ( pass2Key & keyholder)
inline

update the encryption key from the pass2Key object by reference

Definition at line 94 of file crypto.h.

◆ setkeyaccess() [2/2]

void crypto::setkeyaccess ( pass2Key * keyholder)
inline

update the encryption key from the pass2Key object by pointer to object

Definition at line 87 of file crypto.h.


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