当前位置: 首页>>代码示例>>C#>>正文


C# Certificate.Create方法代码示例

本文整理汇总了C#中Certificate.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Certificate.Create方法的具体用法?C# Certificate.Create怎么用?C# Certificate.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Certificate的用法示例。


在下文中一共展示了Certificate.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {

            String serverName = @".";
            String dbName = @"SmoTdeSampleDB";
            String certificateName = @"SmoTdeSampleCert";
                        
            //ScriptingOptions to be used globally
            ScriptingOptions so = new ScriptingOptions();
            so.IncludeHeaders = true;
            so.IncludeIfNotExists = true;


            //Getting the Server Object
            Server server = new Server(serverName);

            //Creating new Database
            Database db = new Database(server, dbName);
            db.Create();

            Database masterDb = server.Databases["Master"];
         
            //Creating certificate 
            Certificate certificate = new Certificate(masterDb, certificateName);
            certificate.StartDate = DateTime.Today;
            certificate.Subject = "My certificate";
            certificate.Create();
                       
            try
            {
                //Create Database Encryption 
                DatabaseEncryptionKey dbEk = new DatabaseEncryptionKey();
                dbEk.Parent = db;
                dbEk.EncryptionAlgorithm = DatabaseEncryptionAlgorithm.Aes256;
                dbEk.EncryptionType = DatabaseEncryptionType.ServerCertificate;
                dbEk.EncryptorName = certificateName;

                Console.WriteLine("Scripting Database Encryption Key Status \n");
                StringCollection sc = dbEk.Script(so);

                Console.WriteLine("T-SQL for create\n");
                foreach (string s in sc)
                {
                    Console.WriteLine(s);
                }
                dbEk.Create();

                //Changing the execution mode to Execute and Capture Sql
                //This is just to capture T-SQL , can skip this if wanted.
                server.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteAndCaptureSql;

                //Altering EncryptionKey
                db.DatabaseEncryptionKey.EncryptionAlgorithm = DatabaseEncryptionAlgorithm.TripleDes;
                db.DatabaseEncryptionKey.EncryptionType = DatabaseEncryptionType.ServerCertificate;
                db.DatabaseEncryptionKey.EncryptorName = certificateName;
                db.DatabaseEncryptionKey.Alter();

                //Showing the TSQL generated
                Console.WriteLine("\nT-SQL for Alter\n");
                foreach (string s in server.ConnectionContext.CapturedSql.Text)
                {
                    Console.WriteLine(s);
                }

                //Clearing the already stored TSQL
                server.ConnectionContext.CapturedSql.Clear();

                //Changing the execution mode back to normal
                server.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;

                //ALtering the EncryptionAlgorithm directly
                db.DatabaseEncryptionKey.Regenerate(DatabaseEncryptionAlgorithm.Aes256);
                                
                
            }
            finally
            {
                db.Drop();
                masterDb.Certificates[certificateName].Drop();
             }

        }
开发者ID:rcdosado,项目名称:SMO,代码行数:82,代码来源:SmoTdeSampleTest.cs

示例2: Create

        //Creates a certificate on current database
        public void Create()
        {
            if (!database.Certificates.Contains(this.Name))
            {
                // Create service contract
                Certificate cert = new Certificate(database, this.Name);
                cert.ActiveForServiceBrokerDialog = true;
                
                cert.StartDate = this.StartDate;
                cert.ExpirationDate = this.ExpirationDate;

                if (!String.IsNullOrEmpty(this.Owner) && this.Owner.ToString() != "(not used)")
                    cert.Owner = this.Owner;

                cert.Subject = this.Subject;
                cert.Create();
            }
        }
开发者ID:rcdosado,项目名称:SMO,代码行数:19,代码来源:CertificateConfiguration.cs

示例3: UpDateSsb

        int UpDateSsb()
        {
            updatedobj = null;
              //if (!isDirty)
            //return 0;
              if (!ValidateData()) {
            Cursor crs = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try {
              Database db = null;

              ServiceBroker sb = null;
              if (ssbType != SsbEnum.Database && ssbType != SsbEnum.Login && ssbType != SsbEnum.EndPoint) {
             sb = dBase.ServiceBroker;
              }
              switch (ssbType) {
            case SsbEnum.Database:
              MasterKey mk = null;
              SSBIDatabase sbd = null;
              if (isEdit) {
                sbd = (SSBIDatabase)objToUpdate;
                db = sbd.DataBase;
              }
              else {
                db = new Database();
                db.Name = txtName.Text;
                db.Parent = dbServ.SMOServer;
              }

              if (isEdit) {
               if(db.MasterKey != null && db_chkMasterKey.Checked == false) {
                 mk = db.MasterKey;
                 mk.Drop();

               }
               else if (db.MasterKey == null && db_chkMasterKey.Checked) {
                 mk = new MasterKey();
                 mk.Parent = db;
                 mk.Create(db_txtMkPwd.Text);
               }

               db.Alter();
               if (sbd.IsTrustworthy != db_chkTrustWorthy.Checked)
                 sbd.IsTrustworthy = db_chkTrustWorthy.Checked;

              }
              else {
                db.Create();
                sbd = new SSBIDatabase(db);

                if (db_chkMasterKey.Checked) {
                  mk = new MasterKey();
                  mk.Parent = db;
                  mk.Create(db_txtMkPwd.Text);

                }

                if (db_chkTrustWorthy.Checked) {
                  sbd.IsTrustworthy = true;
                }

              }
              if (dBase == null)
                dBase = db;

              //Server serv = db.Parent;

              updatedobj = db;
              break;
            case SsbEnum.MessageType:
              MessageType mt = null;
              if (isEdit)
                mt = (MessageType)objToUpdate;
              else {
                mt = new MessageType();
                mt.Parent = sb;
                mt.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                mt.Owner = cboUser.Text;
              mt.MessageTypeValidation = (MessageTypeValidation)Enum.Parse(typeof(MessageTypeValidation), cboVal.Text);
              if (cboValSchema.Enabled)
                mt.ValidationXmlSchemaCollection = cboValSchema.Text;

              if (isEdit)
                mt.Alter();
              else
                mt.Create();
              updatedobj = mt;
              break;

            case SsbEnum.Contract:
              ServiceContract sc = new ServiceContract();
              sc.Parent = sb;
              sc.Name = txtName.Text;
              if (cboUser.Text != string.Empty)
                sc.Owner = cboUser.Text;
              //get the message types
              foreach (DataGridViewRow row in dvMsgTypes.Rows) {
//.........这里部分代码省略.........
开发者ID:nberglund,项目名称:ssbadmin,代码行数:101,代码来源:Form2.cs


注:本文中的Certificate.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。