DES encryption of 8 bytes plain text results in 16 bytes array

懵懂的女人 提交于 2019-12-23 12:42:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1262594/des-encryption-of-8-bytes-plain-text-results-in-16-bytes-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!