public void DecryptRecord(byte[] fragment, out byte[] dcrFragment, out byte[] dcrMAC) { var fragmentSize = 0; var paddingLength = 0; // Decrypt message fragment ( fragment + mac [+ padding + padding_length] ) DecryptionCipher.TransformBlock(fragment, 0, fragment.Length, fragment, 0); // optimization: decrypt "in place", worst case: padding will reduce the size of the data // this will cut in half the memory allocations (dcrFragment and dcrMAC remains) // Calculate fragment size if (CipherMode == CipherMode.CBC) { // Calculate padding_length paddingLength = fragment[fragment.Length - 1]; fragmentSize = fragment.Length - (paddingLength + 1) - HashSize; } else { fragmentSize = fragment.Length - HashSize; } dcrFragment = new byte[fragmentSize]; dcrMAC = new byte[HashSize]; Buffer.BlockCopy(fragment, 0, dcrFragment, 0, dcrFragment.Length); Buffer.BlockCopy(fragment, dcrFragment.Length, dcrMAC, 0, dcrMAC.Length); }
public void DecryptRecord(byte[] fragment, out byte[] dcrFragment, out byte[] dcrMAC) { int num = 0; int num2 = 0; DecryptionCipher.TransformBlock(fragment, 0, fragment.Length, fragment, 0); if (CipherMode == CipherMode.CBC) { num2 = fragment[fragment.Length - 1]; num = fragment.Length - (num2 + 1) - HashSize; } else { num = fragment.Length - HashSize; } dcrFragment = new byte[num]; dcrMAC = new byte[HashSize]; Buffer.BlockCopy(fragment, 0, dcrFragment, 0, dcrFragment.Length); Buffer.BlockCopy(fragment, dcrFragment.Length, dcrMAC, 0, dcrMAC.Length); }