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


C# SecureString.MakeReadOnly方法代码示例

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


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

示例1: CreateSelfSignCertificate

		public static byte[] CreateSelfSignCertificate(string distinguishedName, DateTime startTime, DateTime endTime, string insecurePassword)
		{
			SecureString password = null;
			try
			{
				if (!string.IsNullOrEmpty(insecurePassword))
				{
					password = new SecureString();
					foreach (char ch in insecurePassword)
					{
						password.AppendChar(ch);
					}

					password.MakeReadOnly();
				}

				return CreateSelfSignCertificate(distinguishedName, startTime, endTime, password);
			}
			finally
			{
				if (password != null)
				{
					password.Dispose();
				}
			}
		}
开发者ID:Galigator,项目名称:db4o,代码行数:26,代码来源:Certificates.cs

示例2: Main

        static void Main(string[] args)
        {
            // The SecureString is used with a using statement,
            // so the Dispose method is called when you are done with the string
            // so that it doesn’t stay in memory any longer then strictly necessary.
            using (SecureString ss = new SecureString())
            {
                Console.WriteLine("Please enter password: ");
                while(true)
                {
                    ConsoleKeyInfo cki = Console.ReadKey(true);
                    if (cki.Key == ConsoleKey.Enter) break;

                    ss.AppendChar(cki.KeyChar);
                    Console.Write("*");
                }
                ss.MakeReadOnly();

                Console.WriteLine();

                ConvertToUnsecureString(ss);
            }

            Console.ReadLine();
        }
开发者ID:nissbran,项目名称:Training-Certifications,代码行数:25,代码来源:Program.cs

示例3: Decrypt

        public static SecureString Decrypt(this string cipher)
        {
            if (cipher == null) throw new ArgumentNullException("cipher");

            byte[] saltInclusive = Convert.FromBase64String(cipher);
            MemoryStream ms;

            byte[] entropy;
            byte[] data;

            using (ms = new MemoryStream(saltInclusive))
            {
                BinaryReader reader = new BinaryReader(ms, Encoding.Unicode);
                entropy = reader.ReadBytes(16);
                data = reader.ReadBytes(saltInclusive.Length - 16);
            }

            byte[] decrypted = ProtectedData.Unprotect(data, entropy, DataProtectionScope.CurrentUser);

            SecureString secured = new SecureString();

            int count = Encoding.Unicode.GetCharCount(decrypted);
            int bc = decrypted.Length / count;

            for (int i = 0; i < count; i++)
                secured.AppendChar(Encoding.Unicode.GetChars(decrypted, i * bc, bc)[0]);

            secured.MakeReadOnly();

            return secured;
        }
开发者ID:kakesu,项目名称:Procurement,代码行数:31,代码来源:DPAPI.cs

示例4: SetAzureAutomationCredentialByNameWithParametersSuccessfull

        public void SetAzureAutomationCredentialByNameWithParametersSuccessfull()
        {
            // Setup
            string accountName = "automation";
            string credentialName = "credential";
            string username = "testUser";
            string password = "password";
            string description = "desc";

            var secureString = new SecureString();
            Array.ForEach(password.ToCharArray(), secureString.AppendChar);
            secureString.MakeReadOnly();

            var value = new PSCredential(username, secureString);

            this.mockAutomationClient.Setup(f => f.UpdateCredential(accountName, credentialName, username, password, description));

            // Test
            this.cmdlet.AutomationAccountName = accountName;
            this.cmdlet.Name = credentialName;
            this.cmdlet.Description = description;
            this.cmdlet.Value = value;
            this.cmdlet.ExecuteCmdlet();

            // Assert
            this.mockAutomationClient.Verify(f => f.UpdateCredential(accountName, credentialName, username, password, description), Times.Once());
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:27,代码来源:SetAzureAutomationCredentialTest.cs

示例5: DecryptSecure

        /// <span class="code-SummaryComment"><summary></span>
        /// Decrypts a base64 encrypted string and returns the decrpyted data
        /// wrapped into a <span class="code-SummaryComment"><see cref="SecureString"/> instance.</span>
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name="cipher">A base64 encoded string that was created</span>
        /// through the <span class="code-SummaryComment"><see cref="Encrypt(string)"/> or</span>
        /// <span class="code-SummaryComment"><see cref="Encrypt(SecureString)"/> extension methods.</param></span>
        /// <span class="code-SummaryComment"><returns>The decrypted string, wrapped into a</span>
        /// <span class="code-SummaryComment"><see cref="SecureString"/> instance.</returns></span>
        /// <span class="code-SummaryComment"><exception cref="ArgumentNullException">If <paramref name="cipher"/></span>
        /// is a null reference.<span class="code-SummaryComment"></exception></span>
        public static SecureString DecryptSecure(this string cipher)
        {
            if (cipher == null) throw new ArgumentNullException("cipher");

            //parse base64 string
            byte[] data = Convert.FromBase64String(cipher);

            //decrypt data
            byte[] decrypted = ProtectedData.Unprotect(data, null, Scope);

            SecureString ss = new SecureString();

            //parse characters one by one - doesn't change the fact that
            //we have them in memory however...
            int count = Encoding.Unicode.GetCharCount(decrypted);
            int bc = decrypted.Length / count;
            for (int i = 0; i < count; i++)
            {
                ss.AppendChar(Encoding.Unicode.GetChars(decrypted, i * bc, bc)[0]);
            }

            //mark as read-only
            ss.MakeReadOnly();
            return ss;
        }
开发者ID:Alucard1766,项目名称:CleanLoad,代码行数:36,代码来源:SecurityExtensions.cs

示例6: NewAzureAutomationCertificateByNameSuccessfull

        public void NewAzureAutomationCertificateByNameSuccessfull()
        {
            // Setup
            string resourceGroupName = "resourceGroup";
            string accountName = "automation";
            string certificateName = "certificate";
            string path = "testCert.pfx";
            string password = "password";
            string description = "desc";

            var secureString = new SecureString();
            Array.ForEach(password.ToCharArray(), secureString.AppendChar);
            secureString.MakeReadOnly();

            this.mockAutomationClient.Setup(
                f => f.CreateCertificate(resourceGroupName, accountName, certificateName, path, secureString, description, false));

            this.cmdlet.ResourceGroupName = resourceGroupName;
            this.cmdlet.AutomationAccountName = accountName;
            this.cmdlet.Name = certificateName;
            this.cmdlet.Description = description;
            this.cmdlet.Path = path;
            this.cmdlet.Password = secureString;
            this.cmdlet.ExecuteCmdlet();

            // Assert
            this.mockAutomationClient.Verify(f => f.CreateCertificate(resourceGroupName, accountName, certificateName, path, secureString, description, false), Times.Once());
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:28,代码来源:NewAzureAutomationCertificateTest.cs

示例7: GetPassword

        public static SecureString GetPassword()
        {
            SecureString pwd = new SecureString();
            while (true)
            {
                ConsoleKeyInfo i = Console.ReadKey(true);
                if (i.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (i.Key == ConsoleKey.Backspace)
                {
                    if (pwd.Length > 0)
                    {
                        pwd.RemoveAt(pwd.Length - 1);
                        Console.Write("\b \b");
                    }
                }
                else
                {
                    pwd.AppendChar(i.KeyChar);
                    Console.Write("*");
                }
            }

            pwd.MakeReadOnly();
            Console.WriteLine();
            return pwd;
        }
开发者ID:lun471k,项目名称:OneClickToProd,代码行数:29,代码来源:Program.cs

示例8: ReadSecureString

 public static SecureString ReadSecureString(string prompt)
 {
     const string t = " !\"#$%&'()*+,-./0123456789:;<=>[email protected][\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
     SecureString securePwd = new SecureString();
     ConsoleKeyInfo key;
     Console.Write(prompt);
     Console.Write(':');
     do
     {
         key = Console.ReadKey(true);
         if (t.IndexOf(key.KeyChar) != -1)
         {
             securePwd.AppendChar(key.KeyChar);
             Console.Write('*');
         }
         else if (key.Key == ConsoleKey.Backspace && securePwd.Length > 0)
         {
             securePwd.RemoveAt(securePwd.Length - 1);
             Console.Write(key.KeyChar);
             Console.Write(' ');
             Console.Write(key.KeyChar);
         }
     } while (key.Key != ConsoleKey.Enter);
     Console.WriteLine();
     securePwd.MakeReadOnly();
     return securePwd;
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:27,代码来源:ConsoleServiceBase.cs

示例9: ReadPasswordFromConsole

        /// <summary>
        /// Read a password from the console and return it as SecureString
        /// </summary>
        /// <returns></returns>
        public static bool ReadPasswordFromConsole(out SecureString secStr)
        {
            secStr = new SecureString();

            for (ConsoleKeyInfo c = Console.ReadKey(true); c.Key != ConsoleKey.Enter; c = Console.ReadKey(true))
            {
                if (c.Key == ConsoleKey.Backspace && secStr.Length > 0)
                    secStr.RemoveAt(secStr.Length - 1);

                if (c.Key == ConsoleKey.Escape)
                {
                    // cancel
                    secStr.Dispose();
                    Console.WriteLine();
                    return false;
                }

                if (!Char.IsControl(c.KeyChar))
                    secStr.AppendChar(c.KeyChar);
            }

            secStr.MakeReadOnly();
            Console.WriteLine();
            return true;
        }
开发者ID:cherepets,项目名称:SeafClient,代码行数:29,代码来源:SecureStringUtils.cs

示例10: EnableRemoteDesktop

        /// <summary>
        /// Invoke the Enable-AzureServiceProjectRemoteDesktop enableRDCmdlet.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="password">Password.</param>
        public static void EnableRemoteDesktop(string username, string password)
        {
            SecureString securePassword = null;
            if (password != null)
            {
                securePassword = new SecureString();
                foreach (char ch in password)
                {
                    securePassword.AppendChar(ch);
                }
                securePassword.MakeReadOnly();
            }

            if (enableRDCmdlet == null)
            {
                enableRDCmdlet = new EnableAzureServiceProjectRemoteDesktopCommand();
                if (mockCommandRuntime == null)
                {
                    mockCommandRuntime = new MockCommandRuntime();
                }
                enableRDCmdlet.CommandRuntime = mockCommandRuntime;
            }

            enableRDCmdlet.Username = username;
            enableRDCmdlet.Password = securePassword;
            enableRDCmdlet.EnableRemoteDesktop();
        }
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:32,代码来源:EnableAzureRemoteDesktopCommandTest.cs

示例11: ExecuteNonQueryProcedure

        public void ExecuteNonQueryProcedure(string procedureName, System.Collections.Specialized.NameValueCollection parametersCollection)
        {
            try
            {
                string password = "wolfstein";
                var pwdarr = password.ToCharArray();
                SecureString securePwd = new SecureString();
                foreach (char c in pwdarr)
                {
                    securePwd.AppendChar(c);
                }
                securePwd.MakeReadOnly();

                using (
                    SqlConnection conn = new SqlConnection(this.db.Database.Connection.ConnectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = procedureName;
                    cmd.CommandType = CommandType.StoredProcedure;
                    foreach (var key in parametersCollection.AllKeys)
                    {
                        cmd.Parameters.AddWithValue(key, parametersCollection[key]);
                    }
                    var result = cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:yuyi1,项目名称:Verdezyne-Operations,代码行数:33,代码来源:PilotPlantStoredProcedure.cs

示例12: Main

        static void Main(string[] args)
        {
            using (SecureString ss = new SecureString())
            {
                Console.WriteLine("Please enter password:");
                while (true)
                {
                    ConsoleKeyInfo cki = Console.ReadKey(true);
                    if (cki.Key == ConsoleKey.Enter)
                    {
                        break;
                    }

                    ss.AppendChar(cki.KeyChar);
                    Console.Write("*");
                }

                ss.MakeReadOnly();
                Console.WriteLine();
                ConvertToUnsecureString(ss);
            }

            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
开发者ID:jbijoux,项目名称:Exam70_483,代码行数:25,代码来源:Program.cs

示例13: Secure

 public static SecureString Secure(this string input)
 {
     var result = new SecureString();
     foreach (var c in input) result.AppendChar(c);
     result.MakeReadOnly();
     return result;
 }
开发者ID:jhgbrt,项目名称:EasyNetQ.Management.Client,代码行数:7,代码来源:StringExtensions.cs

示例14: ToSecureString

 public static SecureString ToSecureString (string value)
 {
   var result = new SecureString ();
   foreach (var c in value)
     result.AppendChar (c);
   result.MakeReadOnly ();
   return result;
 }
开发者ID:aluxnimm,项目名称:outlookcaldavsynchronizer,代码行数:8,代码来源:SecureStringUtility.cs

示例15: GetPassword

 static SecureString GetPassword(string password)
 {
     SecureString spassword = new SecureString();
     foreach (char c in password)
         spassword.AppendChar(c);
     spassword.MakeReadOnly();
     return spassword;
 }
开发者ID:tandis,项目名称:PnP,代码行数:8,代码来源:Functions.cs


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