Ejemplo n.º 1
0
        }         // func EncodeWindowsPassword

        public static SecureString DecodePassword(string passwordValue)
        {
            if (String.IsNullOrEmpty(passwordValue))
            {
                return(null);
            }
            if (passwordValue.Length > 5 && passwordValue[5] == ':')
            {
                var pwdType = passwordValue.Substring(0, 5);
                switch (pwdType)
                {
                case "win0x":
                    return(DecodeWindowsPassword(Procs.ConvertToBytes(passwordValue, 6, passwordValue.Length - 6), true));

                case "win64":
                    return(DecodeWindowsPassword(Convert.FromBase64String(passwordValue.Substring(6, passwordValue.Length - 6)), true));

                case "usr0x":
                    return(DecodeWindowsPassword(Procs.ConvertToBytes(passwordValue, 6, passwordValue.Length - 6), false));

                case "usr64":
                    return(DecodeWindowsPassword(Convert.FromBase64String(passwordValue.Substring(6, passwordValue.Length - 6)), false));

                case "plain":
                    return(passwordValue.CreateSecureString(6, passwordValue.Length - 6));

                default:
                    throw new ArgumentOutOfRangeException("passwordType", pwdType, "Invalid password type.");
                }
            }
            else
            {
                return(passwordValue.CreateSecureString());
            }
        }         // func DecodePassword
Ejemplo n.º 2
0
        }         // func EncodePassword

        #endregion

        #region -- Password Hash ------------------------------------------------------

        public static byte[] ParsePasswordHash(string passwordHash)
        {
            if (String.IsNullOrEmpty(passwordHash))
            {
                return(null);
            }

            if (passwordHash.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
            {
                return(Procs.ConvertToBytes(passwordHash, 2, passwordHash.Length - 2));
            }
            else
            {
                return(Convert.FromBase64String(passwordHash));
            }
        }         // func ParsePasswordHash