|
AES128ESP32 Library
|
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. More...
#include <cryptoAES128.h>
Public Member Functions | |
| cryptoAES128 () | |
| bool | setKeyaccess (pass2Key *keyholder) |
| bool | setKeyaccess (pass2Key &keyholder) |
| bool | getIVbytes (ivData &ivdata) |
| bool | setIVbytes (ivData &ivdata) |
| void | clearIV () |
| bool | Decrypt (encryptedData &encdata, String &rtn) |
| bool | Decrypt (encryptedData *encdata, String &rtn) |
| bool | Encrypt (String datatoEncrypt, encryptedData **) |
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.
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.
To setup the key data call the setkeyaccess()
responsabilities create a pass2Key object create a masterkey (with makeMasterkey() ) 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() function. generate a newkey from the plain text password. deriveNewKeyfromText(). you cannot save the newkey data, it always needs to be generated.
create a cryptoAES128() object set the keys to the crypto object using setKeyaccess() * if you change the pass2Key object (masterKey) you need to update the cryto object again with setKeyaccess() 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 object (masterkey) goes out of scope the cryptoAES128 class will not function. it will probably fail/crash. Thats because the keys (masterkey and crypto key) are deleted when the pass2Key object goes out of scope (deleted)
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, and you should because you will need it to decrypt password: is considered secret, it must never be saved.
Definition at line 58 of file cryptoAES128.h.
| cryptoAES128::cryptoAES128 | ( | ) |
Definition at line 47 of file cryptoAES128.cpp.
| void cryptoAES128::clearIV | ( | ) |
clear the IV bytes, you can either generate a new IV during the Encryption function or set a previously existing IV with setIVBytes
errors: none
Definition at line 113 of file cryptoAES128.cpp.
| bool cryptoAES128::Decrypt | ( | encryptedData & | encdata, |
| String & | rtn ) |
Return the decrypted string. before the decryption can happen the key information and IV must be set. setKeyaccess() setIVBytes()
errors: all errors will be psa specific errors
Definition at line 169 of file cryptoAES128.cpp.
|
inline |
Definition at line 73 of file cryptoAES128.h.
| bool cryptoAES128::Encrypt | ( | String | datatoEncrypt, |
| encryptedData ** | returndata ) |
encrypt the string and return the encrypted bytes. NOTE: example (this example code is outdated - it needs replacing)
errors: all errors will be psa specific errors
Definition at line 223 of file cryptoAES128.cpp.
| bool cryptoAES128::getIVbytes | ( | ivData & | ivdata | ) |
return the IV bytes. If the user has not performed an encrypt operation the IV will not have been generated and will return all 0 bytes. This condition is not an error, it just means there's no IV data. Without an IV it will not be possible to decrypt data, so the user must supply the IV data.
errors: AES128_ERROR1 : the ivdata.size is not valid.
Definition at line 77 of file cryptoAES128.cpp.
| bool cryptoAES128::setIVbytes | ( | ivData & | ivdata | ) |
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.
errors: AES128_ERROR1 : the ivdata.size is not valid.
Definition at line 97 of file cryptoAES128.cpp.
| bool cryptoAES128::setKeyaccess | ( | pass2Key & | keyholder | ) |
update the encryption key from the pass2Key object by reference
errors: AES128_ERROR2 : the newkeyid is not valid.
Definition at line 58 of file cryptoAES128.cpp.
|
inline |
Definition at line 67 of file cryptoAES128.h.