Use this function to encrypt a block of data that comes from string.
Because AES works on blocks of 16 bytes then you get the best performance if the block size that you pass to it is dividable by 16. The class has built in cache technology so it will work if the the block size is not dividable by 8, but it will be slower.
If the total size of all blocks that you encrypt is not dividable by 16 then you will get 1 to 15 unencrypted bytes at the end. Because of that then you should add 15 bytes (PaddingBlockSize-1) of random bytes to the end of the encrypted stream to ensure that all of your data gets encrypted.
After you have finished encrypting all of the blocks then you should call FinishEncrypt which will let the encryptor clean up and it will return all unencrypted bytes there which should be part of the random bytes if you have done as described above.
Because AES can only operate with 128,192 and 256 bit key-sizes then if you do not supply long enough key then the encryption will be guided to next bit-mode bellow, that is here is how it works:
Password length >= 32 bytes (256 bits), then you get 256 bit key.
Password length >= 24 bytes (192 bits) (and less than 32 bytes), then you get 256 bit key.
Password length >= 16 bytes (128 bits) (and less than 24 bytes), then you get 128 bit key.
Password length < 16 bytes, then you get a invalid key which causes invalid encryption.
It is a very good idea to use Hash algorithms to guide the actual password into the desired bit-size to use with the encipher.