Modern encryption algorithms always deal with a sequence of bytes, not with symbols. Consider this MSDN example
public static byte[] EncryptString(SymmetricAlgorithm symAlg, string inString)
{
byte[] inBlock = UnicodeEncoding.Unicode.GetBytes(inString);
ICryptoTransform xfrm = symAlg.CreateEncryptor();
byte[] outBlock = xfrm.TransformFinalBlock(inBlock, 0, inBlock.Length);
return outBlock;
}
In this example the source string is converted to sequence of bytes using Unicode (UTF-16) encoding. This sequence of bytes is encrypted with a symmetric algorithm by TransformFinalBlock() method call.
The important thing here is padding. The MSDN example uses default AES encryption mode setting: CBC mode with random IV and PKCS7 padding. This means that the plain text bytes are processed one AES block (16 bytes) at a time. If the plain text size is not a multiple of 16 bytes the final plain text block is made exactly 16 bytes by adding several bytes to its end. E.g. if the final plain text chunk has 10 bytes, it will be extended by 6 additional bytes. The value of those bytes is the number of bytes added (0x06). If the message length is multiple of 16 bytes a whole padding block will be added. Such block will be filled with value 16 == 0x10.
So with CBC mode and PKCS7 padding 25 plaintext bytes will be always padded to 32 bytes of ciphertext. Have in mind though that IV in this mode should be picked at random for each encrypted string, so the resulting ciphertext must contain 32 + 16 = 48 bytes. In general it is wise to use authenticated encryption. Adding a MAC tag to encrypted text will increase the ciphertext size by additional 16 bytes (at least). So with random IV and MAC the original 25 bytes will become 32 + 16 + 16 = 64 bytes or 512 bits. You will be able to encrypt up to 31 bytes in such way. Encrypting 32..47 bytes will add another block (16 bytes) to the resulting ciphertext.
If such padding mode does not suit your needs you may set padding mode to None
and implement your own padding like this:
Aes myAes = Aes.Create();
myAes.Padding = PaddingMode.None;
byte[] plaintext = Encoding.ASCII.GetBytes(text);
//do something with plaintext so that its length becomes multiple of block size:
byte[] paddedPlaintext = MyPaddingScheme(plaintext);
//Encrypt paddedPlaintext using myAes instance
However I must warn you that bad padding scheme might make your encryption insecure. It is always wiser to adapt some existing construct to your needs.
Naturally the ciphertext will not contain ASCII characters only. You may convert it manually to hex byte by byte or use Convert.ToBase64String()
to store it in a database column.