Skip to content

Commit 630e451

Browse files
committed
fix
1 parent 146af98 commit 630e451

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/DataProtection/DataProtection/src/Cng/CbcAuthenticatedEncryptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,12 @@ public override byte[] Encrypt(ArraySegment<byte> plaintext, ArraySegment<byte>
412412

413413
var size = GetEncryptedSize(plaintext.Count);
414414
var ciphertext = new byte[preBufferSize + size + postBufferSize];
415+
var destination = ciphertext.AsSpan((int)preBufferSize, size);
415416

416417
if (!TryEncrypt(
417418
plaintext: plaintext,
418419
additionalAuthenticatedData: additionalAuthenticatedData,
419-
destination: ciphertext,
420+
destination: destination,
420421
out var bytesWritten))
421422
{
422423
throw Error.CryptCommon_GenericError(new ArgumentException("Not enough space in destination array"));

src/DataProtection/DataProtection/src/Cng/CngGcmAuthenticatedEncryptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,12 @@ public override byte[] Encrypt(ArraySegment<byte> plaintext, ArraySegment<byte>
316316

317317
var size = GetEncryptedSize(plaintext.Count);
318318
var ciphertext = new byte[preBufferSize + size + postBufferSize];
319+
var destination = ciphertext.AsSpan((int)preBufferSize, size);
319320

320321
if (!TryEncrypt(
321322
plaintext: plaintext,
322323
additionalAuthenticatedData: additionalAuthenticatedData,
323-
destination: ciphertext,
324+
destination: destination,
324325
out var bytesWritten))
325326
{
326327
throw Error.CryptCommon_GenericError(new ArgumentException("Not enough space in destination array"));

src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,12 @@ public byte[] Encrypt(ArraySegment<byte> plaintext, ArraySegment<byte> additiona
148148

149149
var size = GetEncryptedSize(plaintext.Count);
150150
var ciphertext = new byte[preBufferSize + size + postBufferSize];
151+
var destination = ciphertext.AsSpan((int)preBufferSize, size);
151152

152153
if (!TryEncrypt(
153154
plaintext: plaintext,
154155
additionalAuthenticatedData: additionalAuthenticatedData,
155-
destination: ciphertext,
156+
destination: destination,
156157
out var bytesWritten))
157158
{
158159
throw Error.CryptCommon_GenericError(new ArgumentException("Not enough space in destination array"));

0 commit comments

Comments
 (0)