Esempio n. 1
0
        static int Encrypt(EncryptParameters p)
        {
            _arguments = p;

            EnsureCanOverwriteDestination(p);

            using (var decryptedStream = new FileStream(p.SourceFileName, FileMode.Open, FileAccess.Read, FileShare.None))
                using (var encryptedStream = new FileStream(p.DestinationFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                    using (var cipher = new EncryptedNewKeyCipher(p.Certificate))
                    {
                        cipher.Base64Encoded = p.Base64Encoded;
                        cipher.Encrypt(decryptedStream, encryptedStream);
                    }

            return(0);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (ParseArguments(args))
            {
                try
                {
                    var cert = GetCert(_certSubject, _certThumbprint);

                    using (var cipher = new EncryptedNewKeyCipher(cert))
                    {
                        if (_base64)
                        {
                            cipher.Base64Encoded = true;
                        }

                        if (_encrypt)
                        {
                            using (var decryptedStream = new FileStream(_clearText, FileMode.Open, FileAccess.Read, FileShare.None))
                                using (var encryptedStream = new FileStream(_encryptedText, FileMode.Create, FileAccess.Write, FileShare.None))
                                    cipher.Encrypt(decryptedStream, encryptedStream);
                        }

                        if (_decrypt)
                        {
                            using (var encryptedStream = new FileStream(_encryptedText, FileMode.Open, FileAccess.Read, FileShare.None))
                                using (var decryptedStream = new FileStream(_decryptedText, FileMode.Create, FileAccess.Write, FileShare.None))
                                    cipher.Decrypt(encryptedStream, decryptedStream);
                        }
                    }
                }
                catch (Exception x)
                {
                    Console.WriteLine(x.ToString());
                    Usage();
                }
            }

#if DEBUG
            Console.WriteLine(Resources.PressAnyKey);
            Console.ReadKey(true);
#endif
        }