Class for AES encryption/decription. Cryprion/Decryption is compatible with System.Security.Cryptography.Aes Some facts about AES for people meeting first time with it:
More...
#include <AES.h>
|
| AES (KeySize keySize, unsigned char *keyBytes, Padding padding=AESPAD_PCKS7, Mode mode=AESM_CBC) |
| Creates new instance of AES class
|
|
int | CryptedSize (int srcSize) |
| Calculates size needed for crypted data array from given input data array size
|
|
int | Crypt (unsigned char *src, int srcOffset, int srcLength, unsigned char *dst, int dstOffset) |
| Crypts bytes from input array and stores them into destination array. Note taht input and output may have different sizes! Use CryptedSize function to calculate space needed for output array
|
|
int | DecryptedSize (unsigned char *cryptedSrc, int cryptedOff, int cryptedLen) |
| Calculates size needed for decryped data array
|
|
int | Decrypt (unsigned char *src, int srcOffset, int srcLength, unsigned char *dst, int dstOffset) |
| Decrypts data from input array and stores decrypted data to output array
|
|
int | ChunkSize () |
| Gets basic chunk size of AES, alwaus 16
|
|
|
unsigned char | CBCInitialVector [16] |
| Gets or sets the cbc initial vector used for bitwise exclusive OR operation with first block. By default if AES is in CBC mode it will be initaly set to value generated form key
|
|
Class for AES encryption/decription. Cryprion/Decryption is compatible with System.Security.Cryptography.Aes Some facts about AES for people meeting first time with it:
- AES chipers 16 byte chunks always and that is not dependent on key size If total number of message bytes is not divisible by 16 some sort of padding will be applied at end so total input array becomes divisible by 16 None - zeroes will be added and you will get this zeroes in decrypted array PCKS7 - X bytes having value X will be added at the end, if original input array is divisible by 16 then 16 bytes having value 16 will be added so 32 bytes to crypt this way will end as 48 bytes of crypted data
- This implementation support CBC and ECB mode of chipering. -ECB means each chunk is chiped separately with KEY - you could extract partial data this way, but it's not recommended because of security weakness -CBC means XOR will be applied on chunk using previous chirped chunk value. For first chunk CBCInitialVector will be used for XOR operation. CBC makes total crypted data sensitive to even single bit change
AES chiper mode type enumerator
- Enumerator:
AESM_ECB |
The Electronic Codebook (ECB) mode encrypts each block individually. Any blocks of plain text that are identical and in the same message, or that are in a different message encrypted with the same key, will be transformed into identical cipher text blocks. Important: This mode is not recommended because it opens the door for multiple security exploits. If the plain text to be encrypted contains substantial repetition, it is feasible for the cipher text to be broken one block at a time. It is also possible to use block analysis to determine the encryption key. Also, an active adversary can substitute and exchange individual blocks without detection, which allows blocks to be saved and inserted into the stream at other points without detection.
|
AESM_CBC |
The Cipher Block Chaining (CBC) mode introduces feedback. Before each plain text block is encrypted, it is combined with the cipher text of the previous block by a bitwise exclusive OR operation. This ensures that even if the plain text contains many identical blocks, they will each encrypt to a different cipher text block. The initialization vector is combined with the first plain text block by a bitwise exclusive OR operation before the block is encrypted. If a single bit of the cipher text block is mangled, the corresponding plain text block will also be mangled. In addition, a bit in the subsequent block, in the same position as the original mangled bit, will be mangled.
|
AES padding type enumerator
Creates new instance of AES class
- Parameters
-
keySize | Defines key size for AES encryption |
keyBytes | Key bytes - must corespond to keySize variable |
padding | The padding algoritham to use - PCKS7 by default |
mode | Cipher mode to use - CBC by default |
int sp2plib::AES::ChunkSize |
( |
| ) |
|
Gets basic chunk size of AES, alwaus 16
int sp2plib::AES::Crypt |
( |
unsigned char * |
src, |
|
|
int |
srcOffset, |
|
|
int |
srcLength, |
|
|
unsigned char * |
dst, |
|
|
int |
dstOffset |
|
) |
| |
Crypts bytes from input array and stores them into destination array. Note taht input and output may have different sizes! Use CryptedSize function to calculate space needed for output array
- Parameters
-
src | Source array |
srcOffset | Index in source array form which to start chipering |
srcLength | Total length of data in source array for crypting |
dst | Destination array |
dstOffset | Start index in destionation array for storing crypted data |
- Returns
- Size of crypted data
int sp2plib::AES::CryptedSize |
( |
int |
srcSize | ) |
|
Calculates size needed for crypted data array from given input data array size
- Parameters
-
srcSize | Size of data array to crypt |
- Returns
- Crypted array size
int sp2plib::AES::Decrypt |
( |
unsigned char * |
src, |
|
|
int |
srcOffset, |
|
|
int |
srcLength, |
|
|
unsigned char * |
dst, |
|
|
int |
dstOffset |
|
) |
| |
Decrypts data from input array and stores decrypted data to output array
- Parameters
-
src | Source array containing crypted data |
srcOffset | Index in source array form which to start dechipering. |
srcLength | Total length of crypted data in source array for decrypting. |
dst | Destination array. |
dstOffset | Start index in destionation array for storing decrypted data. |
- Returns
- Size of decrypted data array
int sp2plib::AES::DecryptedSize |
( |
unsigned char * |
cryptedSrc, |
|
|
int |
cryptedOff, |
|
|
int |
cryptedLen |
|
) |
| |
Calculates size needed for decryped data array
- Parameters
-
cryptedSrc | Crypted data array |
cryptedOff | Start index of cryped data in array |
cryptedLen | Total length of crypted data in array |
- Returns
- .
unsigned char sp2plib::AES::CBCInitialVector[16] |
Gets or sets the cbc initial vector used for bitwise exclusive OR operation with first block. By default if AES is in CBC mode it will be initaly set to value generated form key
The documentation for this class was generated from the following file: