1

I'm trying to understand why the following code results in the encrypted byte array being 16 bytes if plainText is 8 bytes in length. I expected the result to also be 8 bytes in length?

private static byte[] encrypt(byte[] key, byte[] plainText)
{
    try
    {
        using (MemoryStream ms = new MemoryStream())
        {
            DES des = new DESCryptoServiceProvider() { Key = key, IV = key };

            using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
            {
                using(BinaryWriter bw = new BinaryWriter(cs))
                {
                    bw.Write(plainText);
                }
            }

            return ms.ToArray();
        }
    }
    catch (Exception e)
    {
        Logger.LogWarning(e);
        throw e;
    }
}
Taylor Leese
  • 51,004
  • 28
  • 112
  • 141

1 Answers1

3

Already answered in: DES encryption of 8 bytes plain text results in 16 bytes array

Community
  • 1
  • 1
Michael Bray
  • 14,998
  • 7
  • 42
  • 68
  • BTW... I wrote a little app to help me test different encryption algs some time ago... I've posted the source code on QDrive at https://www.qdrive.net/download/sharelinkdownloader.php?id=45392&key=zxF92nDxOmF3Iq86OpB98X8xzmX3MjD6zpN . It's a bit rough, but it works... not highly functional but might have something of use. – Michael Bray Sep 18 '09 at 22:50