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


C# SecureString.Copy方法代码示例

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


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

示例1: WebPageSteganography

        /// <summary>
        /// Initializes a new instance of the <see cref="WebPageSteganography" /> class.
        /// </summary>
        /// <param name="file">A file containing HTML.</param>
        /// <param name="passphrase">The passphrase to use for encryption and decryption.</param>
        public WebPageSteganography(FileInfo file, SecureString passphrase)
        {
            // Update the file info
            this.isFileInfo = true;
            this.webPageFile = new FileInfo(file.FullName);

            // Load the bytes from the file and then reset last access time.
            DateTime created = this.webPageFile.CreationTime;
            DateTime modified = this.webPageFile.LastWriteTime;
            DateTime accessed = this.webPageFile.LastAccessTime;

            BinaryReader readFile = new BinaryReader(File.Open(file.FullName, FileMode.Open));
            this.OriginalBytes = new byte[readFile.BaseStream.Length];
            this.OriginalBytes = readFile.ReadBytes(this.OriginalBytes.Length);
            readFile.Close();

            this.webPageFile.CreationTime = created;
            this.webPageFile.LastWriteTime = modified;
            this.webPageFile.LastAccessTime = accessed;

            // Setup the original steganography bytes
            this.CopyOriginalToStego();

            // Setup the index positions for each steganographic message byte
            uint length = Math.Min(4096, this.Maximum - this.Minimum);
            this.Positions = ChannelTools.MathSetRandom(this.Minimum, this.Maximum, length);

            // Save the password
            this.passphrase = passphrase.Copy();
        }
开发者ID:SimWitty,项目名称:Incog,代码行数:35,代码来源:WebPageSteganography.cs

示例2: ReadLineMasked

        public static SecureString ReadLineMasked(bool useMask, char mask)
        {
            using (var securePassword = new SecureString())
            {
                while (true)
                {
                    var k = Console.ReadKey(true);

                    if (k.Key == ConsoleKey.Enter)
                        break;
                    if (k.Key == ConsoleKey.Escape)
                        return null;

                    if (k.Key == ConsoleKey.Backspace)
                    {
                        if (securePassword.Length > 0)
                        {
                            securePassword.RemoveChar();
                            if (useMask)
                                Console.Write("\b \b");
                        }
                        continue;
                    }

                    securePassword.AppendChar(k.KeyChar);

                    if (useMask)
                        Console.Write(mask);
                }

                if (securePassword.Length > 0)
                    return securePassword.Copy();
                return null;
            }
        }
开发者ID:nikeee,项目名称:nth,代码行数:35,代码来源:ConsoleEx.cs

示例3: ConnectionOptions

 public ConnectionOptions(string locale, string username, SecureString password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) : base(context, timeout)
 {
     if (locale != null)
     {
         this.locale = locale;
     }
     this.username = username;
     this.enablePrivileges = enablePrivileges;
     if (password != null)
     {
         this.securePassword = password.Copy();
     }
     if (authority != null)
     {
         this.authority = authority;
     }
     if (impersonation != ImpersonationLevel.Default)
     {
         this.impersonation = impersonation;
     }
     if (authentication != AuthenticationLevel.Default)
     {
         this.authentication = authentication;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:ConnectionOptions.cs

示例4: HttpServer

 /// <summary>
 /// Initializes a new instance of the <see cref="HttpServer" /> class.
 /// </summary>
 /// <param name="passphrase">The passphrase for encrypting and decrypting.</param>
 public HttpServer(SecureString passphrase)
 {
     this.Address = IPAddress.Any;
     this.Port = 80;
     this.Active = false;
     this.MessageQueue = new Queue();
     this.passphrase = passphrase.Copy();
 }
开发者ID:SimWitty,项目名称:Incog,代码行数:12,代码来源:HttpServer.cs

示例5: ClusterCredentials

        /// <summary>
        /// Initializes a new instance of the <see cref="ClusterCredentials"/> class.
        /// </summary>
        /// <param name="clusterUri">The cluster URI.</param>
        /// <param name="userName">The username.</param>
        /// <param name="password">The password.</param>
        public ClusterCredentials(Uri clusterUri, string userName, SecureString password)
        {
            clusterUri.ArgumentNotNull("clusterUri");
            userName.ArgumentNotNullNorEmpty("username");
            password.ArgumentNotNull("securePassword");

            ClusterUri = clusterUri;
            UserName = userName;
            _clusterPassword = password.Copy();
            _clusterPassword.MakeReadOnly();
        }
开发者ID:gitter-badger,项目名称:hbase-sdk-for-net,代码行数:17,代码来源:ClusterCredentials.cs

示例6: FtpManager

        public FtpManager(string host, int port, string directory, string username, SecureString password, WebProxy proxy, bool usePassiveMode, string transferAssemblyFilePath, int protcol)
        {
            TransferAssemblyPath = transferAssemblyFilePath;
            GetTransferProvider();

            _transferProvider.Host = host;
            _transferProvider.Port = port;
            _transferProvider.Directory = directory;
            _transferProvider.Username = username;
            _transferProvider.Password = password.Copy();
            _transferProvider.Proxy = proxy;
            _transferProvider.UsePassiveMode = usePassiveMode;
            if (String.IsNullOrWhiteSpace(transferAssemblyFilePath))
                Protocol = (FtpSecurityProtocol)protcol;
        }
开发者ID:vainamov,项目名称:nUpdate,代码行数:15,代码来源:FtpManager.cs

示例7: SqlAuthenticationCredentials

        /// <summary>
        /// Initializes a new instance of the <see cref="SqlAuthenticationCredentials" /> class.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="password">The encrypted password.</param>
        public SqlAuthenticationCredentials(string userName, SecureString password)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("userName");
            }

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            this.userName = userName;
            this.password = password.Copy();
            this.password.MakeReadOnly();
        }
开发者ID:B-Rich,项目名称:azure-sdk-tools,代码行数:21,代码来源:DataServiceBasicCredentials.cs

示例8: NativeCimCredentialHandle

		internal NativeCimCredentialHandle(IntPtr handle, bool bIsCertificate, SecureString secureStr) : base(true)
		{
            try
            {
                this.passwordSecureStr = null;
                this.credentialIsCretificate = bIsCertificate;
                if (secureStr != null && secureStr.Length > 0)
                {
                    this.passwordSecureStr = secureStr.Copy();
                }
                this.handle = handle;
            }
            catch
            {

            }
		}
开发者ID:nickchal,项目名称:pash,代码行数:17,代码来源:NativeCimCredentialHandle.cs

示例9: ToSecureString

        /// <summary>
        /// The to secure string.
        /// </summary>
        /// <param name="current">
        /// The current.
        /// </param>
        /// <returns>
        /// </returns>
        public static SecureString ToSecureString(this string current)
        {
            if (current == null)
            {
                current = string.Empty;
            }

            using (var str = new SecureString())
            {
                for (int i = 0; i < current.Length; i++)
                {
                    str.AppendChar(current[i]);
                }

                return str.Copy();
            }
        }
开发者ID:matthid,项目名称:actorvsthreads,代码行数:25,代码来源:StringExtensions.cs

示例10: SecureCredential

        /// <summary>
        /// Constructor
        /// </summary>
        public SecureCredential(string principalName, SecureString password)
        {
            // validate inputs
            if (principalName.Length >
                UnsafeNativeMethods.CREDUI_MAX_USERNAME_LENGTH + UnsafeNativeMethods.CREDUI_MAX_DOMAIN_TARGET_LENGTH)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Properties.Resources.InvalidPrincipalLength,
                    UnsafeNativeMethods.CREDUI_MAX_USERNAME_LENGTH + UnsafeNativeMethods.CREDUI_MAX_DOMAIN_TARGET_LENGTH),
                    "principalName");
            }

            if (password.Length > UnsafeNativeMethods.CREDUI_MAX_PASSWORD_LENGTH)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Properties.Resources.InvalidPasswordLength,
                    UnsafeNativeMethods.CREDUI_MAX_PASSWORD_LENGTH), "password");
            }

            this.principalName = principalName;
            this.password = password.Copy();
            this.password.MakeReadOnly();
            LoadUserDomainValues();
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:25,代码来源:SecureCredential.cs

示例11: SetPassword

        public static void SetPassword(string username, SecureString password)
        {
            string path = Path.Combine(DataPath.AppData, FILE);

            byte[] passwordData;

            if (password.Length > 0)
            {
                byte[] buffer = new byte[2 * password.Length];
                IntPtr ptr = Marshal.SecureStringToBSTR(password);

                try
                {
                    Marshal.Copy(ptr, buffer, 0, buffer.Length);
                }
                finally
                {
                    Marshal.ZeroFreeBSTR(ptr);
                }

                try
                {
                    passwordData = ProtectedData.Protect(buffer, KEY, DataProtectionScope.CurrentUser);
                }
                finally
                {
                    Array.Clear(buffer, 0, buffer.Length);
                }
            }
            else
            {
                passwordData = new byte[0];
            }

            lock (_lock)
            {
                try
                {
                    if (cache == null)
                        cache = new Dictionary<string, SecureString>(StringComparer.OrdinalIgnoreCase);

                    SecureString s = password.Copy();
                    s.MakeReadOnly();

                    cache[username] = s;
                }
                catch { }

                if (storeCredentials)
                {
                    try
                    {
                        using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)))
                        {
                            using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)))
                            {
                                bool hasHeader = false;

                                try
                                {
                                    hasHeader = reader.ReadUInt16() == FILE_HEADER;
                                    if (!hasHeader)
                                        reader.BaseStream.Position = 0;
                                }
                                catch { }

                                ushort count;

                                if (hasHeader)
                                {
                                    long position = reader.BaseStream.Position;
                                    bool hasUsername = false;
                                    count = reader.ReadUInt16();

                                    for (int i = 0; i < count; i++)
                                    {
                                        if (!hasUsername)
                                            writer.BaseStream.Position = reader.BaseStream.Position;

                                        string name = reader.ReadString();
                                        ushort length = reader.ReadUInt16();
                                        byte[] data = reader.ReadBytes(length);

                                        if (hasUsername)
                                        {
                                            writer.Write(name);
                                            writer.Write(length);
                                            writer.Write(data);
                                        }
                                        else if (name.Equals(username, StringComparison.OrdinalIgnoreCase))
                                        {
                                            //all users past this user will be shifted up
                                            //this user will be moved to the end of the file
                                            hasUsername = true;
                                        }
                                    }

                                    if (!hasUsername)
                                        writer.BaseStream.Position = reader.BaseStream.Position;

//.........这里部分代码省略.........
开发者ID:Healix,项目名称:Gw2Launcher,代码行数:101,代码来源:Credentials.cs

示例12: PasswordEvidence

        private readonly string _digest; // used to implement Equals without referring to the SecureString

        // constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="PasswordEvidence" /> class.
        /// </summary>
        /// <param name="password">The password.</param>
        public PasswordEvidence(SecureString password)
        {
            _securePassword = password.Copy();
            _securePassword.MakeReadOnly();
            _digest = GenerateDigest(password);
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:13,代码来源:PasswordEvidence.cs

示例13: UserCredentials

 public UserCredentials(SecureString username, SecureString password, SecureString domain)
 {
     _userName = username.Copy();
     _password = password.Copy();
     DomainName = ConvertToUnsecuredString(domain);
 }
开发者ID:jeffbreece,项目名称:demos,代码行数:6,代码来源:SecureStoreProxy.cs

示例14: ImmutableCredentials

        /// <summary>
        /// Constructs an ImmutableCredentials object with supplied accessKey, secretKey as a SecureString
        /// and an optional session token.
        /// </summary>
        /// <param name="accessKey"></param>
        /// <param name="secretKey"></param>
        /// <param name="token">Optional. Can be set to null or empty for non-session credentials.</param>
        public ImmutableCredentials(string accessKey, SecureString secretKey, string token)
        {
            if (string.IsNullOrEmpty(accessKey)) throw new ArgumentNullException("accessKey");
            if (secretKey == null) throw new ArgumentNullException("secretKey");

            AccessKey = accessKey;
            ClearSecretKey = null;
            SecureSecretKey = secretKey.Copy();
            Token = token ?? string.Empty;
        }
开发者ID:rguarino4,项目名称:aws-sdk-net,代码行数:17,代码来源:AWSCredentials.cs

示例15: OnSecureTextSet

 // Private methods.
 /// <summary>
 /// An event handler called when the text of the secure text box has been set.
 /// </summary>
 /// <param name="text">The new text.</param>
 private void OnSecureTextSet(SecureString text)
 {
     // If the secure text is null.
     if (null == text)
     {
         // Clear the current secure text.
         this.secureText.Clear();
         // Clear the displayed text.
         base.Text = string.Empty;
     }
     else
     {
         // Dispose the previous secure text.
         this.secureText.Dispose();
         // Set the new secure text to a read-write copy of the secure text.
         this.secureText = text.Copy();
         // Update the displayed text.
         base.Text = new string(SecureTextBox.passwordChar, this.secureText.Length);
     }
 }
开发者ID:alexbikfalvi,项目名称:DotNetApi,代码行数:25,代码来源:SecureTextBox.cs


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