Skip to content

Commit fac036e

Browse files
committed
Handle arrays of any size in FakePaddingCryptoTransform.
Closes #24.
1 parent bbd6897 commit fac036e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/formats/Cryptography/FakePaddingCryptoTransform.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int input
4545
// data we want to decrypt into it (leaving the rest zeroed), decrypt the block-sized array, and finally return
4646
// only the 'real' decrypted bytes.
4747

48-
var input = new byte[InputBlockSize];
48+
var inputSpan = inputBuffer.AsSpan(inputOffset, inputCount);
49+
var inputLength = inputSpan.Length;
4950

50-
inputBuffer.AsSpan(inputOffset, inputCount).CopyTo(input);
51+
if (inputLength % InputBlockSize is var rem and not 0)
52+
inputLength += InputBlockSize - rem;
53+
54+
var input = new byte[inputLength];
55+
56+
inputSpan.CopyTo(input);
5157

5258
var result = _transform.TransformFinalBlock(input, 0, input.Length);
5359

0 commit comments

Comments
 (0)