tags:

views:

258

answers:

1

I am using this code to encrypt a 8 bytes PlainText with a 8 bytes Key but the result is always a 16 bytes array.

public static byte[] Encrypt(byte[] PlainText, byte[] key)
{
    MemoryStream ms = new MemoryStream();
    DESCryptoServiceProvider mDES = new DESCryptoServiceProvider();
    mDES.Mode = CipherMode.ECB;
    mDES.Key = key;

    CryptoStream encStream = new CryptoStream(ms, mDES.CreateEncryptor(), CryptoStreamMode.Write);
    BinaryWriter bw = new BinaryWriter(encStream);

    bw.Write(PlainText);
    bw.Close();
    encStream.Close();

    byte[] buffer = ms.ToArray();
    ms.Close();

    return buffer;
}

The first 8 bytes of the ouptut is what I expect but the rest I don't what it is.. is it something wrong with this code?

+7  A: 

The input will be padded to the next block size using PKCS padding. 7 bytes input will be padded to 8. 8-15 to 16. 16-23 to 24 and so on and so forth.

Remus Rusanu
Great!, adding mDES.Padding = PaddingMode.None works.. Thanks
eledu81