55using System . Security . Cryptography ;
66using Microsoft . IdentityModel . Logging ;
77
8+ #if NET9_0_OR_GREATER
9+ using System . Threading ;
10+ #endif
11+
812namespace Microsoft . IdentityModel . Tokens
913{
1014 /// <summary>
@@ -15,9 +19,13 @@ public class SymmetricKeyWrapProvider : KeyWrapProvider
1519 private static readonly byte [ ] _defaultIV = new byte [ ] { 0xA6 , 0xA6 , 0xA6 , 0xA6 , 0xA6 , 0xA6 , 0xA6 , 0xA6 } ;
1620 private const int _blockSizeInBits = 64 ;
1721 private const int _blockSizeInBytes = _blockSizeInBits >> 3 ;
18- private static readonly object _encryptorLock = new object ( ) ;
19- private static readonly object _decryptorLock = new object ( ) ;
20-
22+ #if NET9_0_OR_GREATER
23+ private static readonly Lock s_encryptorLock = new ( ) ;
24+ private static readonly Lock s_decryptorLock = new ( ) ;
25+ #else
26+ private static readonly object s_encryptorLock = new ( ) ;
27+ private static readonly object s_decryptorLock = new ( ) ;
28+ #endif
2129 private Lazy < SymmetricAlgorithm > _symmetricAlgorithm ;
2230 private ICryptoTransform _symmetricAlgorithmEncryptor ;
2331 private ICryptoTransform _symmetricAlgorithmDecryptor ;
@@ -259,7 +267,7 @@ Return an error
259267
260268 if ( _symmetricAlgorithmDecryptor == null )
261269 {
262- lock ( _decryptorLock )
270+ lock ( s_decryptorLock )
263271 {
264272 if ( _symmetricAlgorithmDecryptor == null )
265273 _symmetricAlgorithmDecryptor = _symmetricAlgorithm . Value . CreateDecryptor ( ) ;
@@ -409,7 +417,7 @@ private byte[] WrapKeyPrivate(byte[] inputBuffer, int inputOffset, int inputCoun
409417
410418 if ( _symmetricAlgorithmEncryptor == null )
411419 {
412- lock ( _encryptorLock )
420+ lock ( s_encryptorLock )
413421 {
414422 if ( _symmetricAlgorithmEncryptor == null )
415423 _symmetricAlgorithmEncryptor = _symmetricAlgorithm . Value . CreateEncryptor ( ) ;
0 commit comments