コード例 #1
0
        public void TestDateEncryption()
        {
            var piiProcessor = new PIIProcessing(_key);

            var target = new Entity("contact")
            {
                Id                         = Guid.NewGuid(),
                ["name"]                   = "The name",
                ["deb_idnumber"]           = "The id",
                ["documentbody"]           = "The document body",
                ["birthdate"]              = new DateTime(2019, 1, 25),
                ["name_encrypted"]         = "The name encrypted",
                ["deb_idnumber_encrypted"] = "The ID encrypted",
                ["documentbody_encrypted"] = "The docbody encrypted",
                ["date_encrypted"]         = "",
            };

            var original  = target.Clone();
            var encrypted = piiProcessor.EncryptEntity(target, null, s => Debug.WriteLine(s));

            Assert.IsTrue(original.Id.Equals(encrypted.Id));

            foreach (var attr in new[] { "name", "documentbody", "name_encrypted", "documentbody_encrypted" })
            {
                Debug.WriteLine($"Attribute: {attr}");
                Assert.IsTrue(encrypted.Attributes.ContainsKey(attr), $"Missing {attr}");
                Assert.IsTrue(original.Attributes[attr].Equals(encrypted.Attributes[attr]));
            }

            Assert.AreEqual("******", encrypted.Attributes["deb_idnumber"]);
            Assert.AreNotEqual("The ID Encrypted", encrypted.Attributes["deb_idnumber_encrypted"]);
            Assert.AreEqual(new DateTime(1900, 1, 1), encrypted.Attributes["birthdate"]);
            Assert.AreNotEqual("The ID Encrypted", encrypted.Attributes["deb_birthdate_encrypted"]);
            Debug.WriteLine(encrypted.GetAttributeValue <string>("deb_birthdate_encrypted"));

            // Now decrypt the encrypted entity.
            var decrypted = piiProcessor.DecryptEntity(target, s => Debug.WriteLine(s));

            // Assert that deb_idnumber (and other fields) should be as they were.
            foreach (var attr in new[] { "name", "documentbody", "name_encrypted", "documentbody_encrypted", "deb_idnumber", "birthdate" })
            {
                Debug.WriteLine($"Attribute: {attr}");
                Assert.IsTrue(decrypted.Attributes.ContainsKey(attr), $"Missing {attr}");
                if (!original.Attributes[attr].Equals(decrypted.Attributes[attr]))
                {
                    Assert.IsTrue(original.Attributes[attr].Equals(decrypted.Attributes[attr]));
                }
            }
            Assert.AreNotEqual("The ID Encrypted", encrypted.Attributes["deb_birthdate_encrypted"]);
            Assert.AreEqual(decrypted.Attributes["deb_birthdate_encrypted"], encrypted.Attributes["deb_birthdate_encrypted"]);
        }
コード例 #2
0
        public void TestAnnotationEncryption()
        {
            var piiProcessor = new PIIProcessing(_key);

            var target = new Entity("annotation")
            {
                Id               = Guid.NewGuid(),
                ["name"]         = "The name",
                ["deb_idnumber"] = "The id",
                ["documentbody"] = "The document body can be very very long",
                // ["birthdate"] = new DateTime(2019,1,25),
                ["name_encrypted"]         = "The name encrypted",
                ["deb_idnumber_encrypted"] = "The ID encrypted",
                ["documentbody_encrypted"] = "The docbody encrypted",
                ["date_encrypted"]         = "",
            };

            var original = target.Clone();
            var preImage = new Entity("annotation")
            {
                ["filename"] = "PersonalID.jpg"
            };
            var encrypted = piiProcessor.EncryptEntity(target, preImage, s => Debug.WriteLine(s));

            Assert.IsTrue(original.Id.Equals(encrypted.Id));

            foreach (var attr in new[] { "name", "deb_idnumber", "name_encrypted", "documentbody_encrypted", "deb_idnumber_encrypted" })
            {
                Debug.WriteLine($"Attribute: {attr}");
                Assert.IsTrue(encrypted.Attributes.ContainsKey(attr), $"Missing {attr}");
                Assert.IsTrue(original.Attributes[attr].Equals(encrypted.Attributes[attr]));
            }

            Assert.AreNotEqual(original.Attributes["documentbody"], encrypted.Attributes["documentbody"]);

            // Now decrypt the encrypted entity.
            var decrypted = piiProcessor.DecryptEntity(target, s => Debug.WriteLine(s));

            // Assert that deb_idnumber (and other fields) should be as they were.
            foreach (var attr in original.Attributes.Keys)
            {
                Debug.WriteLine($"Attribute: {attr}");
                Assert.IsTrue(encrypted.Attributes.ContainsKey(attr), $"Missing {attr}");
                Assert.IsTrue(original.Attributes[attr].Equals(encrypted.Attributes[attr]));
            }
        }
コード例 #3
0
        private void DecryptPIIForSingleEntity(LocalPluginContext localContext, int stage, Action <string> trace,
                                               IPluginExecutionContext context)
        {
            if (!context.OutputParameters.ContainsKey("BusinessEntity"))
            {
                trace("PluginExecutionContext does not contain BusinessEntity in OutputParameters");
            }
            else
            {
                var target        = (Entity)context.OutputParameters["BusinessEntity"];
                var PIIProcessing = new PIIProcessing(encryptionKey);

                if (stage == PostOperation)
                {
                    PIIProcessing.DecryptEntity(target, trace);
                }
            }
        }