{"record":{"id":"e83807fe90b3174b","repo":"jstedfast/MailKit","slug":"can-only-transform-8-bytes-at-a-time","errorCode":null,"errorMessage":"Can only transform 8 bytes at a time.","messagePattern":"Can only transform 8 bytes at a time\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/DES.cs","lineNumber":117,"sourceCode":"\t\t\t}\n\n\t\t\tpublic int OutputBlockSize {\n\t\t\t\tget { return 8; }\n\t\t\t}\n\n\t\t\tpublic int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)\n\t\t\t{\n\t\t\t\tif (inputBuffer == null)\n\t\t\t\t\tthrow new ArgumentNullException (\"inputBuffer\");\n\n\t\t\t\tif (inputOffset < 0 || inputOffset > inputBuffer.Length)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputOffset\");\n\n\t\t\t\tif (inputCount < 0 || inputOffset > inputBuffer.Length - inputCount)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputCount\");\n\n\t\t\t\tif (inputCount != 8)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputCount\", \"Can only transform 8 bytes at a time.\");\n\n\t\t\t\tif (outputBuffer == null)\n\t\t\t\t\tthrow new ArgumentNullException (\"outputBuffer\");\n\n\t\t\t\tif (outputOffset < 0 || outputOffset > outputBuffer.Length - 8)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"outputOffset\");\n\n\t\t\t\treturn engine.ProcessBlock (inputBuffer, inputOffset, outputBuffer, outputOffset);\n\t\t\t}\n\n\t\t\tpublic byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)\n\t\t\t{\n\t\t\t\tif (inputBuffer == null)\n\t\t\t\t\tthrow new ArgumentNullException (\"inputBuffer\");\n\n\t\t\t\tif (inputOffset < 0 || inputOffset > inputBuffer.Length)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputOffset\");\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/DES.cs#L99-L135","documentation":"DES is a strict 64-bit block cipher, so MailKit's TransformBlock only accepts exactly 8 bytes per call and throws ArgumentOutOfRangeException with message \"Can only transform 8 bytes at a time.\" when inputCount != 8. This follows .NET's block-cipher contract where a block transform processes one block per invocation.","triggerScenarios":"Calling TransformBlock with any inputCount other than 8 (e.g., 16 to 'transform two blocks', or a leftover 3-byte tail of a stream).","commonSituations":"Trying to process a whole buffer in one call instead of looping in 8-byte chunks; passing a non-padded plaintext length; porting code from a streaming cipher that accepted arbitrary lengths.","solutions":["Loop over the input in 8-byte chunks, calling TransformBlock once per chunk.","Pad input to a multiple of 8 bytes (NTLM usage pads per its spec) or route the final partial block through TransformFinalBlock as appropriate.","If transforming multiple blocks, call TransformBlock repeatedly rather than passing a larger count."],"exampleFix":"// before\ndes.TransformBlock(data, 0, data.Length, output, 0); // data.Length may be > 8\n\n// after\nfor (int i = 0; i + 8 <= data.Length; i += 8)\n    des.TransformBlock(data, i, 8, output, i);","handlingStrategy":"validation","validationCode":"if (data.Length % 8 != 0) throw new InvalidOperationException(\"DES input must be padded to a multiple of 8 bytes\");\nfor (int i = 0; i < data.Length; i += 8)\n    des.TransformBlock(data, i, 8, output, i);","typeGuard":"static bool IsBlockAligned(byte[] b) => b != null && b.Length % 8 == 0;","tryCatchPattern":"try {\n    des.TransformBlock(data, 0, 8, output, 0);\n} catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains(\"8 bytes\")) {\n    // wrong chunk size: fix the loop stride to 8\n}","preventionTips":["Always use a chunk size of exactly 8 for DES block transforms.","Pad inputs per the protocol spec (NTLM pads to 8-byte multiples) before transforming.","Never call a block transform with multi-block counts; loop instead."],"tags":["mailkit","ntlm","des","block-size"],"backgroundTag":"invalid-argument-value","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}