Ejemplo n.º 1
0
        protected override int Execute(CmdLineInput input)
        {
            var inPath = input.Args.GetSingle("file");
            var buffer = File.ReadAllBytes(inPath);
            var algorithmName = input.Options.GetSingle("algorithm").GetSingle("name");
            var algorithm = SymmetricAlgorithm.Create(algorithmName);
            var credentials = GetCredentials(input);
            var iterations = int.Parse(input.Options.GetSingle("iterations").GetSingle("count"));
            var legalKeySize = algorithm.LegalKeySizes.Single();
            algorithm.Key = GetBytes(credentials.Password, legalKeySize.MinSize, legalKeySize.MaxSize);
            var legalBlockSize = algorithm.LegalBlockSizes.Single();
            algorithm.IV = GetBytes(credentials.Salt, legalBlockSize.MinSize, legalBlockSize.MaxSize);

            var cryptoTransform = GetCryptoTransform(algorithm);
            for (var i = 0; i < iterations; i++)
            {
                buffer = cryptoTransform.TransformFinalBlock(buffer, 0, buffer.Length);
            }
            var outPath = GetOutputPath(inPath,input);
            File.WriteAllBytes(outPath, buffer);
            return 0;
        }
Ejemplo n.º 2
0
        private static Credentials GetCredentials(CmdLineInput input)
        {
            var credentials = new Credentials();

            CmdLineOption cmdLineOption;
            if (input.Options.TryGetSingle("password", out cmdLineOption))
            {
                credentials.Password = cmdLineOption.GetSingle("value");
                credentials.Salt = input.Options.TryGetSingle("salt", out cmdLineOption)
                                       ? cmdLineOption.GetSingle("salt")
                                       : string.Empty;
                return credentials;
            }

            credentials.Password = PromptFor("Password");
            credentials.Salt = PromptFor("Salt");
            return credentials;
        }
Ejemplo n.º 3
0
 private string GetOutputPath(string inPath, CmdLineInput input)
 {
     CmdLineOption option;
     return input.Options.TryGetSingle("output", out option)
                ? option.GetSingle("path")
                : GetOutputPath(inPath);
 }