AES Encryption
http://msdn.microsoft.com/msdnmag/code/?url=http://msdn.microsoft.com/msdnmag/issues/03/11/AES/Default.aspx
using this lib, it gives junk characters for larger texts as the encryption key size (128,192,256) increased.
The Encrypt and Decrypt Code is as follows:
textBox1 - TEXt you input in.
textBox2 - Encrypted text.
textBox2 - Decrypted text.
void Encrypt()
{
if (radioButton1.Checked)
keysize = Aes.KeySize.Bits128;
else if (radioButton2.Checked)
keysize = Aes.KeySize.Bits192;
else
keysize = Aes.KeySize.Bits256;
byte[] plainText = new byte[16];
byte[] cipherText = new byte[16];
int i = 0; string sPart = "";
string sText = textBox1.Text.Trim();
int nMod = sText.Length % 8;
if (nMod != 0) {
int nQuotient = sText.Length / 8;
int nTobePadded = 8 * (nQuotient + 1);
sText = sText.PadRight(nTobePadded , ' ');
}
for (i = 0; i <= (sText.Length-8); i = i + 8)
{
sPart = sText.Substring(i, 8);
plainText = Encoding.Unicode.GetBytes(sPart);
AesLib.Aes a = new Aes(keysize, new byte[16]);
a.Cipher(plainText, cipherText);
textBox2.Text = textBox2.Text + Encoding.Unicode.GetString(cipherText);
}
}
void Decrypt()
{
if (radioButton1.Checked)
keysize = Aes.KeySize.Bits128;
else if (radioButton2.Checked)
keysize = Aes.KeySize.Bits192;
else
keysize = Aes.KeySize.Bits256;
byte[] cipherText = new byte[16];
byte[] decipheredText = new byte[16];
int i = 0; string sPart = "";
for (i = 0; i <= (textBox2.Text.Length - 8); i = i + 8)
{
sPart = textBox2.Text.Substring(i, 8);
cipherText = Encoding.Unicode.GetBytes(sPart);
AesLib.Aes a = new Aes(keysize, new byte[16]);
a.InvCipher(cipherText, decipheredText);
textBox3.Text = textBox3.Text + Encoding.Unicode.GetString(decipheredText); ;
}
}
Please See the attachment for the junk it gives for larger texts! Any help would be appreciated!
PLEASE HELP!

