예제 #1
0
        static void Main(string[] args)
        {
            ICrypto crypto =
                new SymmetricCrypto(new[] { new Credential(() => Convert.FromBase64String("1J9Og/OaZKWdfdwM6jWMpvlr3q3o7r20xxFDN7TEj6s=")) });

            Person person = new Person
            {
                FirstName = "J",
                LastName  = "Public",
                SSN       = "123-45-6789"
            };

            string xml = SerializeXml(person);

            Console.WriteLine("Original XML:");
            Console.WriteLine(xml);
            Console.WriteLine();

            string encryptedXml = crypto.EncryptXml(xml, "/Person/SSN");

            Console.WriteLine("Encrypted XML:");
            Console.WriteLine(encryptedXml);
            Console.WriteLine();

            string decryptedXml = crypto.DecryptXml(encryptedXml, "/Person/SSN");

            Console.WriteLine("Decrypted XML:");
            Console.WriteLine(decryptedXml);
            Console.WriteLine();

            string json = SerializeJson(person);

            Console.WriteLine("Original JSON:");
            Console.WriteLine(json);
            Console.WriteLine();

            string encryptedJson = crypto.EncryptJson(json, "$.SSN");

            Console.WriteLine("Encrypted JSON:");
            Console.WriteLine(encryptedJson);
            Console.WriteLine();

            string decryptedJson = crypto.DecryptJson(encryptedJson, "$.SSN");

            Console.WriteLine("Decrypted JSON:");
            Console.WriteLine(decryptedJson);
            Console.WriteLine();
        }