2 implementations of IKey
Microsoft.AspNetCore.DataProtection (1)
KeyManagement\Key.cs (1)
18internal sealed class Key : IKey
Microsoft.AspNetCore.DataProtection.Tests (1)
KeyManagement\KeyRingTests.cs (1)
94private sealed class MyKey : IKey
171 references to IKey
KeyManagementSample (2)
Program.cs (2)
39foreach (var key in allKeys) 57foreach (var key in allKeys)
Microsoft.AspNetCore.DataProtection (52)
AuthenticatedEncryption\AuthenticatedEncryptorFactory.cs (1)
36public IAuthenticatedEncryptor? CreateEncryptorInstance(IKey key)
AuthenticatedEncryption\CngCbcAuthenticatedEncryptorFactory.cs (1)
36public IAuthenticatedEncryptor? CreateEncryptorInstance(IKey key)
AuthenticatedEncryption\CngGcmAuthenticatedEncryptorFactory.cs (1)
36public IAuthenticatedEncryptor? CreateEncryptorInstance(IKey key)
AuthenticatedEncryption\IAuthenticatedEncryptorFactory.cs (3)
15/// Creates an <see cref="IAuthenticatedEncryptor"/> instance based on the given <see cref="IKey.Descriptor"/>. 19/// For a given <see cref="IKey.Descriptor"/>, any two instances returned by this method should 23IAuthenticatedEncryptor? CreateEncryptorInstance(IKey key);
AuthenticatedEncryption\ManagedAuthenticatedEncryptorFactory.cs (1)
31public IAuthenticatedEncryptor? CreateEncryptorInstance(IKey key)
KeyManagement\DefaultKeyResolver.cs (11)
93private bool CanCreateAuthenticatedEncryptor(IKey key, ref int retriesRemaining) 107nameof(IKey.CreateEncryptor), 108new InvalidOperationException($"{nameof(IKey.CreateEncryptor)} returned null.")); 133_logger.KeyIsIneligibleToBeTheDefaultKeyBecauseItsMethodFailed(key.KeyId, nameof(IKey.CreateEncryptor), exceptions is null ? ex : new AggregateException(exceptions)); 137_logger.RetryingMethodOfKeyAfterFailure(key.KeyId, nameof(IKey.CreateEncryptor), ex); 148private IKey? FindDefaultKey(DateTimeOffset now, IEnumerable<IKey> allKeys, out IKey? fallbackKey) 160var preferredDefaultKey = (from key in allKeys 212public DefaultKeyResolution ResolveDefaultKeyPolicy(DateTimeOffset now, IEnumerable<IKey> allKeys) 215var defaultKey = FindDefaultKey(now, allKeys, out retVal.FallbackKey);
KeyManagement\IDeletableKeyManager.cs (1)
47bool DeleteKeys(Func<IKey, bool> shouldDelete);
KeyManagement\IKeyManager.cs (2)
26IKey CreateNewKey(DateTimeOffset activationDate, DateTimeOffset expirationDate); 32IReadOnlyCollection<IKey> GetAllKeys();
KeyManagement\Internal\CacheableKeyRing.cs (2)
18internal CacheableKeyRing(CancellationToken expirationToken, DateTimeOffset expirationTime, IKey defaultKey, IEnumerable<IKey> allKeys)
KeyManagement\Internal\DefaultKeyResolution.cs (4)
16/// If this property is non-null, its <see cref="IKey.CreateEncryptor()"/> method will succeed 19public IKey? DefaultKey; 27/// If this property is non-null, its <see cref="IKey.CreateEncryptor()"/> method will succeed 30public IKey? FallbackKey;
KeyManagement\Internal\IDefaultKeyResolver.cs (1)
17DefaultKeyResolution ResolveDefaultKeyPolicy(DateTimeOffset now, IEnumerable<IKey> allKeys);
KeyManagement\Internal\IInternalXmlKeyManager.cs (1)
21IKey CreateNewKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate);
KeyManagement\Key.cs (3)
16/// The basic implementation of <see cref="IKey"/>. 32/// The basic implementation of <see cref="IKey"/>, where the <see cref="IAuthenticatedEncryptorDescriptor"/> 54/// The basic implementation of <see cref="IKey"/>, where the incoming XML element
KeyManagement\KeyExtensions.cs (1)
10public static bool IsExpired(this IKey key, DateTimeOffset now)
KeyManagement\KeyRing.cs (5)
20public KeyRing(IKey defaultKey, IEnumerable<IKey> allKeys) 23foreach (IKey key in allKeys) 66private readonly IKey _key; 69internal KeyHolder(IKey key)
KeyManagement\KeyRingProvider.cs (8)
81private CacheableKeyRing CreateCacheableKeyRingCore(DateTimeOffset now, IKey? keyJustAdded) 89var defaultKey = defaultKeyPolicy.DefaultKey; 99var keyToUse = defaultKey ?? defaultKeyPolicy.FallbackKey ?? keyJustAdded; 138var keyToUse = defaultKey ?? defaultKeyPolicy.FallbackKey; 158var newKey = _keyManager.CreateNewKey(activationDate: now, expirationDate: now + _newKeyLifetime); 166var newKey = _keyManager.CreateNewKey(activationDate: defaultKey.ExpirationDate, expirationDate: now + _newKeyLifetime); 171private CacheableKeyRing CreateCacheableKeyRingCoreStep2(DateTimeOffset now, CancellationToken cacheExpirationToken, IKey defaultKey, IEnumerable<IKey> allKeys)
KeyManagement\XmlKeyManager.cs (6)
145public IKey CreateNewKey(DateTimeOffset activationDate, DateTimeOffset expirationDate) 164public IReadOnlyCollection<IKey> GetAllKeys() 168return processed.OfType<IKey>().ToList().AsReadOnly(); 414public bool DeleteKeys(Func<IKey, bool> shouldDelete) 443if (obj is IKey key) 504IKey IInternalXmlKeyManager.CreateNewKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate)
Microsoft.AspNetCore.DataProtection.Tests (117)
AuthenticatedEncryption\CngCbcAuthenticatedEncryptorFactoryTest.cs (2)
20var key = new Mock<IKey>(); 38var key = new Mock<IKey>();
AuthenticatedEncryption\CngGcmAuthenticatedEncryptorFactoryTest.cs (2)
20var key = new Mock<IKey>(); 38var key = new Mock<IKey>();
AuthenticatedEncryption\ManagedAuthenticatedEncryptorFactoryTest.cs (2)
18var key = new Mock<IKey>(); 35var key = new Mock<IKey>();
KeyManagement\DefaultKeyResolverTests.cs (37)
23var resolution = resolver.ResolveDefaultKeyPolicy(DateTimeOffset.Now, new IKey[0]); 35var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 36var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 51var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 52var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 67var key1 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 82var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 97var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 98var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z", isRevoked: true); 99var key3 = CreateKey("2016-03-01 00:00:00Z", "2016-03-02 00:00:00Z"); // key expires too soon 114var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 115var key2 = CreateKey("2015-03-02 00:00:00Z", "2016-03-01 00:00:00Z", isRevoked: true); 129var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 130var key2 = CreateKey("2015-03-02 00:00:00Z", "2016-03-01 00:00:00Z", createEncryptorThrows: true); 146var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 161var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 176var key1 = CreateKey("2015-03-01 00:00:00Z", "2014-03-01 00:00:00Z"); // expiration before activation should never occur 177var key2 = CreateKey("2015-03-01 00:01:00Z", "2015-04-01 00:00:00Z", isRevoked: true); 178var key3 = CreateKey("2015-03-01 00:02:00Z", "2015-04-01 00:00:00Z"); 193var key1 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-01 00:00:00Z"); 194var key2 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-02 00:00:00Z"); 195var key3 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-03 00:00:00Z", isRevoked: true); 196var key4 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-04 00:00:00Z"); 210var key1 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-01 00:00:00Z"); 211var key2 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-02 00:00:00Z"); 212var key3 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-03 00:00:00Z", createEncryptorThrows: true); 213var key4 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-04 00:00:00Z"); 229var key1 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-03 00:00:00Z", isRevoked: true); 230var key2 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-04 00:00:00Z"); 231var key3 = CreateKey("2010-01-01 00:00:00Z", "2010-01-01 00:00:00Z", creationDate: "2000-01-05 00:00:00Z"); 266var key1 = CreateKey(activation1, expiration1, creationDate: creation1); 267var key2 = CreateKey(activation2, expiration2, creationDate: creation2, createEncryptorThrows: true); 453private static IKey CreateKey(string activationDate, string expirationDate, string creationDate = null, bool isRevoked = false, bool createEncryptorThrows = false) 458private static IKey CreateKey(DateTimeOffset activationDate, DateTimeOffset expirationDate, DateTimeOffset? creationDate = null, bool isRevoked = false, bool createEncryptorThrows = false) 460var mockKey = new Mock<IKey>(); 486public static DefaultKeyResolution ResolveDefaultKeyPolicy(this IDefaultKeyResolver resolver, string now, params IKey[] allKeys) 488return resolver.ResolveDefaultKeyPolicy(DateTimeOffset.ParseExact(now, "u", CultureInfo.InvariantCulture), (IEnumerable<IKey>)allKeys);
KeyManagement\KeyRingBasedDataProtectorTests.cs (9)
204mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 232mockEncryptorFactory.Setup(m => m.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 257mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 288mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 324mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 391mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 432mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(mockEncryptor.Object); 479mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(mockEncryptor.Object); 528mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(mockEncryptor.Object);
KeyManagement\KeyRingProviderTests.cs (52)
25var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 26var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 36Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 63var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 64var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 74Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 79Tuple.Create(key1.ExpirationDate, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 107var allKeys1 = new IKey[0]; 109var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 110var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 122Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys1, new DefaultKeyResolution() 127Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys2, new DefaultKeyResolution() 155var allKeys1 = Array.Empty<IKey>(); 158var newKey = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z", isRevoked: true); 170Tuple.Create(now, (IEnumerable<IKey>)allKeys1, new DefaultKeyResolution() 175Tuple.Create(now, (IEnumerable<IKey>)allKeys2, new DefaultKeyResolution() 198var allKeys = new IKey[0]; 200var newlyCreatedKey = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 211Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 216Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 244var allKeys = new IKey[0]; 255Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 280var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 283var key2 = CreateKey("2016-03-01 00:00:00Z", "2017-03-01 00:00:00Z"); 295Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys1, new DefaultKeyResolution() 300Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys2, new DefaultKeyResolution() 329var key1 = CreateKey("2015-03-01 00:00:00Z", "2016-03-01 00:00:00Z"); 339Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 367var key1 = CreateKey("2015-03-01 00:00:00Z", "2015-03-01 00:00:00Z"); 377Tuple.Create((DateTimeOffset)now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 446var key1 = CreateKey(activation1, expiration1); 447var key2 = CreateKey(activation2, expiration2); 449var generatedKey = CreateKey(expiration1, now + TimeSpan.FromDays(90)); 458var resolveDefaultKeyPolicyReturnValues = new List<Tuple<DateTimeOffset, IEnumerable<IKey>, DefaultKeyResolution>>() 460Tuple.Create(now, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 472Tuple.Create(expiration1, (IEnumerable<IKey>)allKeys, new DefaultKeyResolution() 490Tuple.Create(now, (IEnumerable<IKey>)allKeysAfterGeneration, new DefaultKeyResolution() 528var key = CreateKey(activation, expiration); 529var generatedKey = CreateKey(expiration, now + TimeSpan.FromDays(90)); 542Tuple.Create(now, (IEnumerable<IKey>)allKeysBefore, new DefaultKeyResolution() 547Tuple.Create(now, (IEnumerable<IKey>)allKeysAfter, new DefaultKeyResolution() 755IEnumerable<IReadOnlyCollection<IKey>> getAllKeysReturnValues, 756IEnumerable<Tuple<DateTimeOffset, DateTimeOffset, IKey>> createNewKeyCallbacks, 757IEnumerable<Tuple<DateTimeOffset, IEnumerable<IKey>, DefaultKeyResolution>> resolveDefaultKeyPolicyReturnValues, 795mockDefaultKeyResolver.Setup(o => o.ResolveDefaultKeyPolicy(It.IsAny<DateTimeOffset>(), It.IsAny<IEnumerable<IKey>>())) 796.Returns<DateTimeOffset, IEnumerable<IKey>>((now, allKeys) => 881mockEncryptorFactory.Setup(m => m.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 898mockEncryptorFactory.Setup(m => m.CreateEncryptorInstance(It.IsAny<IKey>())).Returns(new Mock<IAuthenticatedEncryptor>().Object); 920private static IKey CreateKey() 928private static IKey CreateKey(string activationDate, string expirationDate, bool isRevoked = false) 936private static IKey CreateKey(DateTimeOffset activationDate, DateTimeOffset expirationDate, bool isRevoked = false) 938var mockKey = new Mock<IKey>();
KeyManagement\XmlKeyManagerTests.cs (13)
119var newKey = ((IInternalXmlKeyManager)keyManager).CreateNewKey( 217var newKey = ((IInternalXmlKeyManager)keyManager).CreateNewKey( 595private static IReadOnlyCollection<IKey> RunGetAllKeysCore(string xml, IActivator activator, ILoggerFactory loggerFactory = null) 811var createdKey = keyManager.CreateNewKey(activationDate, expirationDate); 821var fetchedKey = Assert.Single(fetchedKeys); 834var fetchedKey2 = Assert.Single(fetchedKeys2); 911var fetchedKey = Assert.Single(fetchedKeys); 922var fetchedKey2 = Assert.Single(fetchedKeys2); 948var key1 = keyManager.CreateNewKey(activationTime, activationTime.AddMinutes(10)); 950var key2 = keyManager.CreateNewKey(activationTime, activationTime.AddMinutes(10)); 952var key3 = keyManager.CreateNewKey(activationTime, activationTime.AddMinutes(10)); 953var key4 = keyManager.CreateNewKey(activationTime, activationTime.AddMinutes(10)); 1041public IAuthenticatedEncryptor CreateEncryptorInstance(IKey key)