Skip to content

Commit 8f5b762

Browse files
committed
re-review
1 parent 8d275ac commit 8f5b762

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/DataProtection/DataProtection/src/Managed/ManagedAuthenticatedEncryptor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,17 @@ public byte[] Encrypt(ArraySegment<byte> plaintext, ArraySegment<byte> additiona
416416
additionalAuthenticatedData.Validate();
417417
var plainTextSpan = plaintext.AsSpan();
418418

419+
#if NET10_0_OR_GREATER
420+
var size = GetEncryptedSize(plainTextSpan.Length);
421+
var retVal = new byte[size];
422+
423+
if (!TryEncrypt(plainTextSpan, additionalAuthenticatedData.AsSpan(), retVal, out var bytesWritten))
424+
{
425+
throw Error.CryptCommon_PayloadInvalid();
426+
}
427+
428+
return retVal;
429+
#else
419430
try
420431
{
421432
var keyModifierLength = KEY_MODIFIER_SIZE_IN_BYTES;
@@ -494,6 +505,7 @@ public byte[] Encrypt(ArraySegment<byte> plaintext, ArraySegment<byte> additiona
494505
// Homogenize all exceptions to CryptographicException.
495506
throw Error.CryptCommon_GenericError(ex);
496507
}
508+
#endif
497509
}
498510

499511
private void CalculateAndValidateMac(

src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CngAuthenticatedEncryptorBaseTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Text;
54
using Moq;
65

76
namespace Microsoft.AspNetCore.DataProtection.Cng.Internal;

0 commit comments

Comments
 (0)