Below Code is Working Fine in c#.NET
byte[] key = Encoding.ASCII.GetByte("012345678901234567890123"); //24characters
byte[] plainText = Encoding.ASCII.GetBytes("lasaa");
TripleDES des = TripleDES.Create();
des.Key = key;
des.Mode = CipherMode.CBC;
ICryptoTransform ic = des.CreateEncryptor();
byte[] enc = ic.TransformFinalBlock(plainText, 0, plainText.Length);
MessageBox.Show(UTF8Encoding.UTF8.GetString(enc));
My questions regarding above are...
- How can I specify KeySize? if i use
des.KeySize=
128
or192
or256
it gives
Specified key is not a valid size for this algorithm
- If I change character length in key by adding more (ex:40 chars). It gives error
Specified key is not a valid size for this algorithm
I want to know why is this happen?