public Task ExecuteAsync(SharedDataKey sharedDataKey, ChangeSharedDataKeyCommandDdto changeSharedDataKeyCommandDdto) { _validator.ValidateAndThrow(changeSharedDataKeyCommandDdto); sharedDataKey.Change(new ChangeSharedDataKeyDdto { Value = changeSharedDataKeyCommandDdto.Value }); return(Task.CompletedTask); }
public Task <SharedDataKey> ExecuteAsync(CreateSharedDataKeyCommandDdto createSharedDataKeyCommandDdto) { _validator.ValidateAndThrow(createSharedDataKeyCommandDdto); SharedDataKey sharedDataKey = SharedDataKey.Create(new CreateSharedDataKeyDdto { Name = createSharedDataKeyCommandDdto.Name, Value = createSharedDataKeyCommandDdto.Value }); return(Task.FromResult(sharedDataKey)); }
public async Task <DataKey> GetSharedAsync(string name) { SharedDataKey sharedDataKey = await _sharedDataKeyQueryRepository.GetSingleAsync(s => s.Name == name); if (sharedDataKey != null) { return(new DataKey { Name = sharedDataKey.Name, Value = sharedDataKey.Value }); } return(null); }
public async Task ExecuteAsync() { using (ITransaction transaction = _transactionManager.Create()) { try { IList <SharedDataKey> existingKeys = (await _commandRepository.GetAsync()).ToList(); foreach (FieldInfo fieldInfo in typeof(Library.Core.Domain.DataProtectors.SharedDataKeys).GetFields()) { string keyName = fieldInfo.GetRawConstantValue().ToString(); SharedDataKey key = existingKeys.SingleOrDefault(k => k.Name == keyName); if (key == null) { SharedDataKey sharedDataKey = await _createSharedDataKeyCommand.ExecuteAsync(new CreateSharedDataKeyCommandDdto { Name = keyName, Value = _encryptionFactory.CreateKey() }); await _commandRepository.AddAsync(sharedDataKey); } else { await _changeSharedDataKeyCommand.ExecuteAsync(key, new ChangeSharedDataKeyCommandDdto { Value = _encryptionFactory.CreateKey() }); await _commandRepository.UpdateAsync(key); } } transaction.Commit(); } catch (Exception) { _logger.LogCritical("Unable to initialise shared data keys"); throw; } } }
public async Task <DataKey> GetAsync(string name) { using (ITransaction transaction = _transactionManager.Create()) { try { if (name == MasterDataKeys.Master) { return(new DataKey { Name = MasterDataKeys.Master, Value = (await _masterKeyProvider.GetAsync()).Value }); } SharedDataKey sharedDataKey = await _queryRepository.GetSingleAsync(s => s.Name == name); if (sharedDataKey == null) { throw new DataKeyNotFoundException(name); } transaction.Commit(); return(new DataKey { Name = sharedDataKey.Name, Value = sharedDataKey.Value }); } catch (Exception e) { throw new DataKeyNotFoundException(name, e); } } }