c# - Sequential .NET DESCryptoServiceProvider encryption and decryption produces wrong bytes after 96th -
basically, here code:
des des = new descryptoserviceprovider(); passwordderivebytes pdb = new passwordderivebytes(new byte[]{123}, new byte[0]); des.iv = new byte[8]; des.key = pdb.cryptderivekey("des", "md5", 0, des.iv); byte[] = enumerable.range(1, 100).select(i => (byte)i).concat(new byte[4]).toarray(); byte[] b = new byte[a.length]; byte[] c = new byte[a.length]; using (var encryptor = des.createencryptor()) encryptor.transformblock(a, 0, a.length, b, 0); using (var decryptor = des.createdecryptor()) decryptor.transformblock(b, 0, b.length, c, 0); (int = 0; < a.length; i++) if (a[i] != c[i]) debugger.break();
it breaks @ i == 96
. why?
another small question: omitting of .concat(new byte[4])
causes first transformblock throw argumentexception. why can't encrypt array of sorted bytes without 4 zeroes @ end?
des block cypher of 64bit blocks, therefore data encoded needs multiple of 64bit blocks. (see http://en.wikipedia.org/wiki/data_encryption_standard)
looking @ 96, assume last block different based on fact padding 100 (not 64bit block) 104 (64bit block) not setting values of last 4 bytes 0.
hope helps,
Comments
Post a Comment