Please note that the problem I encountered is related to the key size. At first, based on the comments included in the code below, I realized that my key should be 24 bytes (192 bits). This did not work, so I gave 16, 32 and 8 byte keys a shot - nothing works. By “not working,” I mean that after my text has been encrypted and decrypted, it does not have the same meaning as my source text.
Example:
Source text: 'Example test this should work '
Ciphertext: ¸¹pÕô6
Decrypted text: 'Example '
Here are two functions that I use (encryption / decryption functions). I will also describe how I call each function.
public byte[] TripleDesEncryptOneBlock(byte[] plainText, byte[] key)
{
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.KeySize = 192;
des.Key = key;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
ICryptoTransform ic = des.CreateEncryptor();
byte[] enc = ic.TransformFinalBlock(plainText, 0, 8);
return enc;
}
public byte[] TripleDesDecryptBlock(byte[] plainText, byte[] key)
{
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.KeySize = 192;
des.Key = key;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
ICryptoTransform ic = des.CreateDecryptor();
byte[] dec = ic.TransformFinalBlock(plainText, 0, 8);
return dec;
}
textBox5.Text = ByteToString(TripleDesEncryptOneBlock(StringToByte(textBox5.Text), StringToByte("1 2 3 4 5 6 7 8 9 1 1 2 ")));
textBox5.Text = ByteToString(TripleDesDecryptBlock(StringToByte(textBox5.Text), StringToByte("1 2 3 4 5 6 7 8 9 1 1 2 ")));
Thanks for any help,
Evan
user725913