Exemplo n.º 1
0
        public byte[] Encrypt(byte[] data, KeyParameters parameters)
        {
            Ensure.ArgumentNotNull(parameters, "parameters");

            var key = _keyGenerator.Generate(parameters.Password, parameters.Salt, parameters.KeySize);
            var iv  = _keyGenerator.Generate(parameters.Password, parameters.Salt, parameters.IVSize);

            return(Encrypt(data, key, iv));
        }
Exemplo n.º 2
0
        public Entity <TKey, TEntity> Add(TEntity value)
        {
            TKey key = _generator.Generate();

            _underlying.Add(key, value);
            return(new Entity <TKey, TEntity>(key, value));
        }
Exemplo n.º 3
0
        public async Task <bool> Handle(ICreateCommand <T> command)
        {
            await _keyGenerator.Generate(command.NewEntity());

            await Collection.InsertOneAsync(command.NewEntity());

            return(true);
        }
Exemplo n.º 4
0
 private ManifestInfo CreateManifest(string contentJson, ManifestMetadata metadata)
 {
     try
     {
         return(JsonConvert.DeserializeObject <ManifestInfo>(
                    contentJson,
                    new JsonSerializerSettings
         {
             Context = new StreamingContext(
                 StreamingContextStates.Other,
                 (_keyGenerator.Generate(metadata), metadata))
         }));
     }
Exemplo n.º 5
0
        public async Task <ValueApiModel> Post(string collectionId, [FromBody] ValueServiceModel model)
        {
            if (model == null)
            {
                throw new InvalidInputException("The request is empty");
            }

            string key = keyGenerator.Generate();

            EnsureValidId(collectionId, key);

            var result = await container.CreateAsync(collectionId, key, model);

            return(new ValueApiModel(result));
        }
        private void StartGenerateKeys()
        {
            options.RsaKeyLength = generateKeysForm.RsaKeyLength;
            var key = keyGenerator.Generate(options.RsaKeyLength, BigNumber.FromInt(options.PublicExponent));

            generateKeysForm.GenerateEnabled = true;
            if (key == null)
            {
                messageHelper.Show("Unable to generate a key.", "Не удалось сгенерировать ключ.");
                return;
            }
            var serializer = new KeySerializer(new BigNumberHexSerializer());

            generateKeysForm.PublicKey  = serializer.SerializePublicKey(key.PublicKey);
            generateKeysForm.PrivateKey = serializer.SerializePrivateKey(key.PrivateKey);
        }
Exemplo n.º 7
0
		public virtual Key Build(CacheItem item, CommandContext commandContext)
		{
			var key = _keyGenerator.Generate(item, commandContext);
			Condition.WithExceptionOnFailure<CachingException>()
				.Requires(key, "generated key")
				.IsNotNull("Key generator failed to produce key.");

			foreach (var keyTransformation in TransformedBy)
			{
				key = keyTransformation.Transform(key, item, commandContext);
				Condition.WithExceptionOnFailure<CachingException>()
					.Requires(key, "transformed key")
					.IsNotNull("Key transformation failed to transform key.");
			}
				
			return key;
		}
Exemplo n.º 8
0
        public string Store(IncludeCombination combination)
        {
            if (combination == null)
            {
                throw new ArgumentNullException("combination");
            }
            var key = _keyGen.Generate(combination.Sources);

            if (!_combinations.ContainsKey(key))
            {
                _combinations.Add(key, combination);
            }
            else
            {
                _combinations[key] = combination;
            }
            return(key);
        }
Exemplo n.º 9
0
 public void Generate_WillThrowWhenInputIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => _keygen.Generate(null));
 }
Exemplo n.º 10
0
 public override void ConfigureCryptor(ReadOnlySpan <byte> password)
 {
     Cryptor.Init(_keyGenerator.Generate(password, Cryptor.Info));
 }
Exemplo n.º 11
0
 public IActionResult GenerateKeys([FromServices] IKeyGenerator keyGenerator)
 {
     return(Ok(keyGenerator.Generate()));
 }
        public async Task <LongRunResult> EnqueueLongRunAsync <TJob, TArgs>(TArgs args,
                                                                            BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null)
            where TJob : LongRunBackgroundJob <TArgs>
        {
            LongRunInfo longRunInfo;
            string      longRunId;

            // i removed try catches for persisting.
            // let it be handled by unit of work and thorwing exceptions
            using (var unitOfWork = UnitOfWorkManager.Begin())
            {
                longRunId   = _keyGenerator.Generate <string>();
                longRunInfo = new LongRunInfo
                {
                    Id = longRunId,
                    //todo: serializer? or json repo?
                    Args          = JsonConvert.SerializeObject(args),
                    LongRunStatus = LongRunStatus.Queued,
                    Type          = typeof(TJob).ToString(),
                };
                await _longRunInfoRepo.InsertAsync(longRunInfo);

                await unitOfWork.CompleteAsync();
            }


            string jobId;

            try
            {
                // try to queue job
                var longRunArgs = new LongRunArgs <TArgs>
                {
                    Args          = args,
                    LongRunInfoId = longRunId
                };
                jobId = await EnqueueAsync <TJob, LongRunArgs <TArgs> >(longRunArgs, priority, delay);
            }
            catch (Exception e)
            {
                try
                {
                    using (var unitOfWork = UnitOfWorkManager.Begin())
                    {
                        longRunInfo = await _longRunInfoRepo.GetAsync(longRunInfo.Id);

                        longRunInfo.LongRunStatus = LongRunStatus.QueueFailed;
                        longRunInfo.Error         = e.ToString();
                        await unitOfWork.CompleteAsync();
                    }
                }
                catch (Exception)
                {
                    //todo: additional handler?
                }
                throw;
            }

            try
            {
                using (var unitOfWork = UnitOfWorkManager.Begin())
                {
                    longRunInfo = await _longRunInfoRepo.GetAsync(longRunInfo.Id);

                    longRunInfo.JobId = jobId;
                    await unitOfWork.CompleteAsync();
                }
            }
            catch (Exception)
            {
                //todo: additional handler?
            }

            return(new LongRunResult
            {
                LongRunId = longRunId,
                JobId = jobId
            });
        }
Exemplo n.º 13
0
        /// <summary>
        /// Generates a unique key.
        /// </summary>
        ///
        /// <typeparam name="T">
        /// Key's type.
        /// </typeparam>
        ///
        /// <param name="keyGeneratorType">
        /// Type of the KeyGenerator to use.
        /// </param>
        ///
        /// <param name="parameters">
        /// Parameters to compute the unique key.
        /// </param>
        ///
        /// <returns>
        /// The unique key.
        /// </returns>
        public static T GenerateKey <T>(Type keyGeneratorType, object[] parameters = null)
        {
            IKeyGenerator <T> keyGenerator = KeyGeneratorHelper.CreateKeyGenerator <T>(keyGeneratorType);

            return(keyGenerator.Generate(parameters));
        }