Esempio n. 1
0
        static int Main(string[] args)
        {
            LogBase logger = LogFactory.GetInstance.CreateSimple("sample.log", false, LogSeverity.SEV_DEBUG);

            Log.SetSingleton(logger);

            Agent agent = new Agent();

            agent.Initialize();

            string input = "Hello World";

            // Setup a Chunk Crypto object to handle Ionic encryption
            ChunkCipherAuto chunkCrypto = new ChunkCipherAuto(agent);

            // Encrypt the string using an Ionic-managed key, and validate the response
            string encryptedText = null;

            try
            {
                chunkCrypto.Encrypt(input, ref encryptedText);
            }
            catch (SdkException e)
            {
                Console.WriteLine("Error encrypting: {0}", e.Message);
                Console.ReadKey();
                return(-2);
            }

            chunkCrypto.Encrypt(input, ref encryptedText);
            Console.WriteLine("Plain Text: {0}", input);
            Console.WriteLine("Ionic Chunk Encrypted Text: {0}", encryptedText);
            Console.ReadKey();
            return(0);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Get the user's home path and password persistor from the environment.
            String homePath = Environment.GetEnvironmentVariable("USERPROFILE");

            String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD");

            if (persistorPassword == null || persistorPassword.Length == 0)
            {
                Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD");
                WaitForInput();
                Environment.Exit(1);
            }

            // Create an agent object to talk to Ionic.
            Agent agent = new Agent();

            // Create a password persistor for agent initialization.
            try
            {
                DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword();
                persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw";
                persistor.Password = persistorPassword;

                agent.SetMetadata(Agent.MetaApplicationName, "IonicHelloWorld Sample");
                agent.Initialize(persistor);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Agent initialization error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Setup the Chunk Crypto object.
            ChunkCipherAuto chunkCrypto = new ChunkCipherAuto(agent);

            string clearText     = "Hello World";
            string encryptedText = null;

            // Encrypt the string using an Ionic-managed key.
            chunkCrypto.Encrypt(clearText, ref encryptedText);

            Console.WriteLine("Plain Text: {0}", clearText);
            Console.WriteLine("Ionic Chunk Encrypted Text: {0}", encryptedText);

            WaitForInput();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Create an agent object to talk to Ionic.
            Agent agent = new Agent();

            try
            {
                agent.SetMetadata(Agent.MetaApplicationName, "C# DefaultPersistor Sample");
                agent.Initialize();
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Agent initialization error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Setup the Chunk Crypto object.
            ChunkCipherAuto chunkCrypto = new ChunkCipherAuto(agent);

            string clearText     = "Hello, World!";
            string encryptedText = null;

            // Define data markings
            AttributesDictionary attributes = new AttributesDictionary();

            attributes.Add("clearance-level", new List <string> {
                "secret"
            });
            ChunkCryptoEncryptAttributes dataMarkings = new ChunkCryptoEncryptAttributes(attributes);

            // Encrypt the string using an Ionic-managed key.
            chunkCrypto.Encrypt(clearText, ref encryptedText, ref dataMarkings);

            string decryptedText = null;

            // Note: Decryption only works if the policy allows it.
            chunkCrypto.Decrypt(encryptedText, ref decryptedText);

            Console.WriteLine("Plain Text: {0}", clearText);
            Console.WriteLine("Ionic Chunk Encrypted Text: {0}", encryptedText);
            Console.WriteLine("Decrypted text: {0}", decryptedText);

            WaitForInput();
        }
Esempio n. 4
0
        static int Main(string[] args)
        {
            // Set input string
            string input = "Hello World!";

            // Setup an agent object to talk to Ionic
            Agent agent = new Agent();

            agent.Initialize();

            // Check if there are profiles.
            if (!agent.HasAnyProfiles)
            {
                Console.WriteLine("There are no device profiles on this device.");
                Console.WriteLine("Register a device before continuing.");
                return(-1);
            }

            // Setup a Chunk Crypto object to handle Ionic encryption
            ChunkCipherAuto chunkCrypto = new ChunkCipherAuto(agent);

            // Encrypt the string using an Ionic-managed key, and validate the response
            string encryptedText = null;

            try
            {
                chunkCrypto.Encrypt(input, ref encryptedText);
            }
            catch (SdkException e)
            {
                Console.WriteLine("Error encrypting: {0}", e.Message);
                Console.ReadKey();
                return(-2);
            }

            Console.WriteLine("Plain Text: {0}", input);
            Console.WriteLine("Ionic Chunk Encrypted Text: {0}", encryptedText);

            Console.WriteLine("Press return to exit.");
            Console.ReadKey();
            return(0);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            string decryptedText = null;
            string encryptedText = "{SET_ENCRYPTED_TEXT_HERE}";

            if (encryptedText == "{SET_ENCRYPTED_TEXT_HERE}")
            {
                Console.WriteLine("You MUST set the output from IonicHelloWorld (or similar to decrypt).");
                Console.ReadKey();
            }
            Agent agent = new Agent();

            agent.Initialize();

            ChunkCipherAuto chunkCrypto = new ChunkCipherAuto(agent);

            chunkCrypto.Decrypt(encryptedText, ref decryptedText);
            Console.WriteLine("Chunk-Encrypted String: ", encryptedText);
            Console.WriteLine("Decrypted String: ", decryptedText);
            Console.ReadKey();
        }
Esempio n. 6
0
        static int Main(string[] args)
        {
            // The message to encrypt.
            String message = "secret message";

            // Get the user's home path and password persistor from the environment.
            String homePath = Environment.GetEnvironmentVariable("USERPROFILE");

            String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD");

            if (persistorPassword == null || persistorPassword.Length == 0)
            {
                Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD");
                WaitForInput();
                Environment.Exit(1);
            }

            // Create an agent object to talk to Ionic.
            Agent agent = new Agent();

            // Create a password persistor for agent initialization.
            try
            {
                DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword();
                persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw";
                persistor.Password = persistorPassword;

                agent.SetMetadata(Agent.MetaApplicationName, "CryptoChunkCipher Sample");
                agent.Initialize(persistor);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Agent initialization error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Create single key without attributes.
            CreateKeysResponse.Key key = null;
            try
            {
                key = agent.CreateKey().Keys[0];
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Key creation error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Initialize chunk cipher object.
            ChunkCipherAuto cipher = new ChunkCipherAuto(agent);

            // Encrypt
            string cipherText = null;

            try
            {
                cipher.Encrypt(message, ref cipherText);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Chunk cipher encrypt error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Decrypt
            string plainText = null;

            try
            {
                cipher.Decrypt(cipherText, ref plainText);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Chunk cipher decrypt error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Verify encrypt and decrypt worked.
            if (message != plainText)
            {
                Console.WriteLine("Encryption/Decrption does not match!");
                Console.WriteLine("Message: {0} - PlainText: {1}", message, plainText);
                WaitForInput();
                Environment.Exit(1);
            }

            Console.WriteLine("CipherText : {0}", cipherText);
            Console.WriteLine("PlainText  : {0}", plainText);

            WaitForInput();
            return(0);
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            string logFilePath = "../../../../../../sample-data/logs/sample.log";
            bool   appendFile  = false;

            // Log SDK to a file with serverity Debug and above.
            LogBase logger = LogFactory.Instance.CreateSimple(logFilePath, appendFile, LogSeverity.SEV_DEBUG);

            Log.SetSingleton(logger);

            // The message to encrypt.
            String message = "top secret message";

            // Get the user's home path and password persistor from the environment.
            String homePath = Environment.GetEnvironmentVariable("USERPROFILE");

            String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD");

            if (persistorPassword == null || persistorPassword.Length == 0)
            {
                Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD");
                WaitForInput();
                Environment.Exit(1);
            }

            // Create an agent object to talk to Ionic.
            Agent agent = new Agent();

            // Create a password persistor for agent initialization.
            try
            {
                DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword();
                persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw";
                persistor.Password = persistorPassword;

                agent.SetMetadata(Agent.MetaApplicationName, "LogSdkCalls Sample");
                agent.Initialize(persistor);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Agent initialization error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Create single key without attributes.
            CreateKeysResponse.Key key = null;
            try
            {
                key = agent.CreateKey().Keys[0];
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Key creation error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Initialize chunk cipher object.
            ChunkCipherAuto cipher = new ChunkCipherAuto(agent);

            // Encrypt
            string cipherText = null;

            try
            {
                cipher.Encrypt(message, ref cipherText);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Chunk cipher encrypt error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Decrypt
            string plainText = null;

            try
            {
                cipher.Decrypt(cipherText, ref plainText);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Chunk cipher decrypt error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Verify encrypt and decrypt worked.
            if (message != plainText)
            {
                Console.WriteLine("Encryption/Decrption does not match!");
                Console.WriteLine("Message: {0} - PlainText: {1}", message, plainText);
                WaitForInput();
                Environment.Exit(1);
            }

            Console.WriteLine("CipherText : {0}", cipherText);
            Console.WriteLine("PlainText  : {0}", plainText);

            WaitForInput();
        }
Esempio n. 8
0
        static int Main(string[] args)
        {
            // Get the user's home path and password persistor from the environment.
            String homePath = Environment.GetEnvironmentVariable("USERPROFILE");

            String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD");

            if (persistorPassword == null || persistorPassword.Length == 0)
            {
                Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD");
                WaitForInput();
                Environment.Exit(1);
            }

            // Create an agent object to talk to Ionic.
            Agent agent = new Agent();

            // Create a password persistor for agent initialization.
            try
            {
                DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword();
                persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw";
                persistor.Password = persistorPassword;

                agent.SetMetadata(Agent.MetaApplicationName, "IonicCiphers Tutorial");
                agent.Initialize(persistor);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Agent initialization error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            /*****************************************************************
            * SENDER
            *****************************************************************/

            // The message to encrypt.
            String message = "this is a secret message!";

            // Initialize chunk sender cipher object.
            ChunkCipherAuto SenderCipher = new ChunkCipherAuto(agent);

            // Encrypt data.
            string cipherText = null;

            try
            {
                SenderCipher.Encrypt(message, ref cipherText);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Chunk sender cipher encrypt error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            Console.WriteLine("CIPHERTEXT : {0}", cipherText);

            /*****************************************************************
            * RECEIVER
            *****************************************************************/

            // Initialize chunk receiver cipher object.
            ChunkCipherAuto recieverCipher = new ChunkCipherAuto(agent);

            // Decrypt data.
            string plainText = null;

            try
            {
                recieverCipher.Decrypt(cipherText, ref plainText);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Chunk receiver cipher decrypt error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            Console.WriteLine("\nPLAINTEXT  : {0}", plainText);

            WaitForInput();
            return(0);
        }