views:

288

answers:

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;
    }
}
+3  A: 

Already answered in: http://stackoverflow.com/questions/1262594/des-encryption-output

Michael Bray
Thanks. Solution in the other thread fixed it.
Taylor Leese
Michael Bray