예제 #1
0
        static int Main(string[] args)
        {
            // Set these however you would like
            string pathToPlainFile     = @"example_file.docx";
            string pathToEncryptedFile = @"example_file_encrypted.docx";

            Agent agent = new Agent();

            agent.Initialize();

            AutoFileCipher fileCipher = new AutoFileCipher(agent);
            // Create a classification
            FileCryptoEncryptAttributes encryptAttributes = new FileCryptoEncryptAttributes();

            encryptAttributes.KeyAttributes["classification"].Add("Restricted");

            // Encrypt the file using the classification, and validate the response
            try
            {
                // We will encrypt file cipher by path overload; see documentation to encrypt byte stream
                fileCipher.Encrypt(pathToPlainFile, pathToEncryptedFile, ref encryptAttributes);
            }
            catch (SdkException e)
            {
                Console.WriteLine("Error encrypting {0}: {1}", pathToPlainFile, e.Message);
                Console.ReadKey();
                return(-2);
            }

            Console.WriteLine("Encrypted file {0} to {1}.", pathToPlainFile, pathToEncryptedFile);
            Console.ReadKey();
            return(0);
        }
예제 #2
0
        static int Main(string[] args)
        {
            // Set these however you would like
            string pathToEncryptedFile = @"example_file_encrypted.docx";
            string pathToDecryptedFile = @"example_file_decrypted.docx";

            Agent agent = new Agent();

            agent.Initialize();

            AutoFileCipher fileCipher = new AutoFileCipher(agent);

            // Decrypt
            try
            {
                FileCryptoDecryptAttributes decryptAttributes = new FileCryptoDecryptAttributes();
                fileCipher.Decrypt(pathToEncryptedFile, pathToDecryptedFile, ref decryptAttributes);
            }
            catch (SdkException e)
            {
                Console.WriteLine("Error decrypting {0}: {1}", pathToEncryptedFile, e.Message);
                Console.ReadKey();
                return(-2);
            }

            Console.WriteLine("Decrypted file {0} to {1}.", pathToEncryptedFile, pathToDecryptedFile);
            Console.ReadKey();
            return(0);
        }