Beispiel #1
0
        public void Run(GenerateKeyVerbOptions options)
        {
            var encryptionType = options.GetAlgorithm();

            if (encryptionType == EnvCryptAlgoEnum.Rsa)
            {
                var rsaKeyPersisterOpts = new AsymmetricKeyFilePersisterOptions()
                {
                    NewKeyName = options.KeyName,
                    NewPrivateKeyFullFilePath = Path.Combine(
                        options.OutputDirectory,
                        string.Concat(options.KeyName, PrivateKeyPostfix)),
                    NewPublicKeyFullFilePath = Path.Combine(
                        options.OutputDirectory,
                        string.Concat(options.KeyName, PublicKeyPostfix)),
                    OverwriteFileIfExists = false
                };

                if (options.OutputKeyToConsole)
                {
                    new GenerateRsaKeyBuilder()
                    .WithKeyPersister(AsymmetricKeyFilePersisterFactory.GetRsaKeyPersister(new ToConsoleTextWriter()))
                    .Build().Run(rsaKeyPersisterOpts);
                }
                else
                {
                    new GenerateRsaKeyBuilder().Build().Run(rsaKeyPersisterOpts);
                }
            }
            else if (encryptionType == EnvCryptAlgoEnum.Aes)
            {
                var aesKeyPersisterOpts = new SymmetricKeyFilePersisterOptions()
                {
                    NewKeyName         = options.KeyName,
                    NewKeyFileFullPath = Path.Combine(
                        options.OutputDirectory,
                        string.Concat(options.KeyName, CommonPostFix)),
                    OverwriteFileIfExists = false
                };

                if (options.OutputKeyToConsole)
                {
                    new GenerateAesKeyBuilder()
                    .WithKeyPersister(SymmetricKeyFilePersisterFactory.GetAesKeyPersister(new ToConsoleTextWriter()))
                    .Build().Run(aesKeyPersisterOpts);
                }
                else
                {
                    new GenerateAesKeyBuilder().Build().Run(aesKeyPersisterOpts);
                }
            }
            else
            {
                System.Console.Error.WriteLine("Unsupported encryption type: {0}", encryptionType);
            }
        }
Beispiel #2
0
        public void Run(SymmetricKeyFilePersisterOptions options)
        {
            Contract.Requires <ArgumentNullException>(options != null, "fileOptions");
            //
            ThrowIfNotBuilt();

            var keyGenerationOptions = new AesKeyGenerationOptions()
            {
                NewKeyName = options.NewKeyName,
                KeySize    = DefaultAesKeySize
            };

            _workflow.Run(keyGenerationOptions, options);
        }