Beispiel #1
0
        private static void KeyGen(Arguments args)
        {
            var key      = Symmetric.GenerateKey(args.PasswordKey, args.Salt);
            var fileText = Convert.ToBase64String(key);

            File.WriteAllText(args.OutputFile, fileText);
        }
Beispiel #2
0
        private static void Encrypt(Arguments args)
        {
            var key          = File.ReadAllText(args.KeyFile);
            var iv           = Symmetric.GenerateIV(args.InitVector);
            var symmetric    = new Symmetric(Convert.FromBase64String(key));
            var plainText    = File.ReadAllText(args.InputFile);
            var cipher       = symmetric.Encrypt(plainText, iv);
            var base64String = Convert.ToBase64String(cipher.ToBytes());

            if (args.Format)
            {
                File.WriteAllLines(args.OutputFile, Symmetric.FormatWithTags(base64String));
            }
            else
            {
                File.WriteAllText(args.OutputFile, base64String);
            }
        }
Beispiel #3
0
        private static void Decrypt(Arguments args)
        {
            var key           = File.ReadAllText(args.KeyFile);
            var lines         = File.ReadAllLines(args.InputFile).ToList();
            var encryptedText = lines.Count > 1 ? Symmetric.RemoveTags(lines) : lines.First();
            var cipher        = new Cipher(Convert.FromBase64String(encryptedText));

            if (!cipher.HasIV && args.InitVector == null)
            {
                throw new ArgumentException("IV Required");
            }

            var iv             = cipher.IV ?? Symmetric.GenerateIV(args.InitVector);
            var symmetric      = new Symmetric(key);
            var decryptedBytes = symmetric.Decrypt(cipher, iv);
            var plainText      = Symmetric.Deserialize <string>(decryptedBytes);

            File.WriteAllText(args.OutputFile, plainText);
        }