public void ExportToXml_BuiltInTypes_ProducesCorrectPayload(Type encryptionAlgorithmType, Type validationAlgorithmType)
        {
            // Arrange
            var masterKey  = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
            var descriptor = new ManagedAuthenticatedEncryptorDescriptor(new ManagedAuthenticatedEncryptorConfiguration()
            {
                EncryptionAlgorithmType    = encryptionAlgorithmType,
                EncryptionAlgorithmKeySize = 2048,
                ValidationAlgorithmType    = validationAlgorithmType
            }, masterKey.ToSecret());

            // Act
            var retVal = descriptor.ExportToXml();

            // Assert
            Assert.Equal(typeof(ManagedAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
            var expectedXml = $@"
                <descriptor>
                  <encryption algorithm='{encryptionAlgorithmType.Name}' keyLength='2048' />
                  <validation algorithm='{validationAlgorithmType.Name}' />
                  <masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
                    <value>{masterKey}</value>
                  </masterKey>
                </descriptor>";

            XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
        }
Example #2
0
        public void ExportToXml_BuiltInTypes_ProducesCorrectPayload(Type encryptionAlgorithmType, Type validationAlgorithmType)
        {
            // Arrange
            var masterKey  = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
            var descriptor = new ManagedAuthenticatedEncryptorDescriptor(new ManagedAuthenticatedEncryptorConfiguration()
            {
                EncryptionAlgorithmType    = encryptionAlgorithmType,
                EncryptionAlgorithmKeySize = 2048,
                ValidationAlgorithmType    = validationAlgorithmType
            }, masterKey);

            // Act
            var retVal = descriptor.ExportToXml();

            // Assert
            Assert.Equal(typeof(ManagedAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
            string expectedXml = string.Format(@"
                <descriptor>
                  <encryption algorithm='{0}' keyLength='2048' />
                  <validation algorithm='{1}' />
                  <masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
                    <value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
                  </masterKey>
                </descriptor>",
                                               encryptionAlgorithmType.Name, validationAlgorithmType.Name);

            XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
        }
        public void ExportToXml_CustomTypes_ProducesCorrectPayload()
        {
            // Arrange
            var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
            var descriptor = new ManagedAuthenticatedEncryptorDescriptor(new ManagedAuthenticatedEncryptionSettings()
            {
                EncryptionAlgorithmType = typeof(MySymmetricAlgorithm),
                EncryptionAlgorithmKeySize = 2048,
                ValidationAlgorithmType = typeof(MyKeyedHashAlgorithm)
            }, masterKey);

            // Act
            var retVal = descriptor.ExportToXml();

            // Assert
            Assert.Equal(typeof(ManagedAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
            string expectedXml = String.Format(@"
                <descriptor>
                  <encryption algorithm='{0}' keyLength='2048' />
                  <validation algorithm='{1}' />
                  <masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
                    <value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
                  </masterKey>
                </descriptor>",
                typeof(MySymmetricAlgorithm).AssemblyQualifiedName, typeof(MyKeyedHashAlgorithm).AssemblyQualifiedName);
            XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
        }