Exemplo n.º 1
0
        private static void HandleEncrypt(Argument arg)
        {
            var isEncrypting = arg.arg == "--encrypt";

            var alg = arg.GetParaOrThrow(0);
            var key = arg.GetParaOrThrow(1);

            var inputFile  = arg.GetParaOrNull(2);
            var outputFile = arg.GetParaOrNull(3) ?? (inputFile != null ? inputFile + ".enc" : null);
            var input      = inputFile.IsNullOrEmpty() ? Console.OpenStandardInput() : File.OpenRead(inputFile);
            var output     = outputFile.IsNullOrEmpty() ? Console.OpenStandardOutput() : File.Open(outputFile, FileMode.Create);

            var encryptStreamFunc = Ss.GetCipherByName(alg).GetEncryptionStreamFunc(key);

            IMyStream from, to;

            if (isEncrypting)
            {
                from = MyStream.FromStream(input);
                to   = encryptStreamFunc(MyStream.FromStream(output));
            }
            else
            {
                from = encryptStreamFunc(MyStream.FromStream(input));
                to   = MyStream.FromStream(output);
            }

            Task.Run(async() => {
                await MyStream.StreamCopy(from, to, -1, true);
                await output.FlushAsync();
                output.Dispose();
            }).Wait();
        }
Exemplo n.º 2
0
 protected override void OnStart()
 {
     base.OnStart();
     getEncryptionStream = Ss.GetCipherByName(encryption).GetEncryptionStreamFunc(key);
 }
Exemplo n.º 3
0
 public override void SetConfig(TomlTable toml)
 {
     base.SetConfig(toml);
     this.enc = Ss.GetCipherByName("aes-256-ctr").GetEncryptorFunc(key);
 }