public void GivenAnEncryptRule_WhenProcess_NodeShouldBeEncrypted()
        {
            AnonymizationFhirPathRule[] rules = new AnonymizationFhirPathRule[]
            {
                new AnonymizationFhirPathRule("Patient.address", "address", "Patient", "encrypt", AnonymizerRuleType.FhirPathRule, "Patient.address"),
            };

            AnonymizationVisitor visitor = new AnonymizationVisitor(rules, CreateTestProcessors());

            var patient     = CreateTestPatient();
            var patientNode = ElementNode.FromElement(patient.ToTypedElement());

            patientNode.Accept(visitor);
            patientNode.RemoveEmptyNodes();

            var patientCity = patientNode.Select("Patient.address[0].city").FirstOrDefault();
            var key         = Encoding.UTF8.GetBytes("1234567890123456");
            var plainValue  = EncryptUtility.DecryptTextFromBase64WithAes(patientCity.Value.ToString(), key);

            Assert.Equal("patienttestcity1", plainValue);

            patient = patientNode.ToPoco <Patient>();
            Assert.Single(patient.Meta.Security);
            Assert.Contains(SecurityLabels.MASKED.Code, patient.Meta.Security.Select(s => s.Code));
        }
        public void GivenAnOriginalText_WhenEncrypt_ResultShouldBeValidAndDecryptable(string originalText)
        {
            var cipherText = EncryptUtility.EncryptTextToBase64WithAes(originalText, Key);
            var plainText  = EncryptUtility.DecryptTextFromBase64WithAes(cipherText, Key);

            Assert.Equal(originalText, plainText);
        }
 public void GivenAInvalidBase64Text_WhenDecrypt_ExceptionShouldBeThrown(string cipherText)
 {
     Assert.Throws <FormatException>(() => EncryptUtility.DecryptTextFromBase64WithAes(cipherText, Key));
 }
        public void GivenAnEncryptedBase64Text_WhenDecrypt_OriginalTextShouldBeReturned(string cipherText, string originalText)
        {
            var plainText = EncryptUtility.DecryptTextFromBase64WithAes(cipherText, Key);

            Assert.Equal(originalText, plainText);
        }
Пример #5
0
 private string DecryptText(string text)
 {
     return(EncryptUtility.DecryptTextFromBase64WithAes(text, Encoding.UTF8.GetBytes(TestEncryptKey)));
 }