示例#1
0
        public static Models.Configuration.KeyMaterialConfiguration ToDomainModel(this Entities.Configuration.KeyMaterialConfiguration entity)
        {
            var model = new Models.Configuration.KeyMaterialConfiguration();

            if (entity == null)
            {
                return(model);
            }

            if (!string.IsNullOrWhiteSpace(entity.SigningCertificateName))
            {
                //var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();
                var cert = X509.CurrentUser.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException(string.Format(Core.Repositories.Resources.Mappings.SigningCertificateNotFoundException, entity.SigningCertificateName));
                }

                model.SigningCertificate = cert;
            }

            if (!string.IsNullOrWhiteSpace(entity.DecryptionCertificateName))
            {
                //var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();
                var cert = X509.CurrentUser.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException(string.Format(Core.Repositories.Resources.Mappings.DecryptionCertificateNotFoundException, entity.DecryptionCertificateName));
                }

                model.DecryptionCertificate = cert;
            }
            else
            {
                model.DecryptionCertificate = null;
            }

            model.SymmetricSigningKey = entity.SymmetricSigningKey;

            return(model);
        }
示例#2
0
        public static Models.Configuration.KeyMaterialConfiguration ToDomainModel(this Entities.Configuration.KeyMaterialConfiguration entity)
        {
            var model = new Models.Configuration.KeyMaterialConfiguration();

            if (entity == null)
            {
                return(model);
            }

            if (!string.IsNullOrWhiteSpace(entity.SigningCertificateName))
            {
                var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException("Signing certificate not found: " + entity.SigningCertificateName);
                }

                model.SigningCertificate = cert;
            }

            if (!string.IsNullOrWhiteSpace(entity.DecryptionCertificateName))
            {
                var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException("Decryption certificate not found: " + entity.DecryptionCertificateName);
                }

                model.DecryptionCertificate = cert;
            }
            else
            {
                model.DecryptionCertificate = null;
            }

            model.SymmetricSigningKey = entity.SymmetricSigningKey;

            return(model);
        }
示例#3
0
        public static Entities.Configuration.KeyMaterialConfiguration ToEntity(this Models.Configuration.KeyMaterialConfiguration model)
        {
            var entity = new Entities.Configuration.KeyMaterialConfiguration();

            if (model.SigningCertificate != null)
            {
                entity.SigningCertificateName = model.SigningCertificate.Subject;
            }

            if (model.DecryptionCertificate != null)
            {
                entity.DecryptionCertificateName = model.DecryptionCertificate.Subject;
            }
            else
            {
                entity.DecryptionCertificateName = null;
            }

            entity.SymmetricSigningKey = model.SymmetricSigningKey;

            return(entity);
        }
        public static Entities.Configuration.KeyMaterialConfiguration ToEntity(this Models.Configuration.KeyMaterialConfiguration model)
        {
            var entity = new Entities.Configuration.KeyMaterialConfiguration();

            if (model.SigningCertificate != null)
            {
                entity.SigningCertificateName = model.SigningCertificate.Subject;
            }

            if (model.DecryptionCertificate != null)
            {
                entity.DecryptionCertificateName = model.DecryptionCertificate.Subject;
            }
            else
            {
                entity.DecryptionCertificateName = null;
            }

            entity.SymmetricSigningKey = model.SymmetricSigningKey;

            return entity;
        }