Пример #1
0
 internal static NtStatus RtlCalculateNtOwfPassword(SafeUnicodeSecureStringPointer password, out byte[] hash)
 {
     SecureUnicodeString unicodePassword = new SecureUnicodeString(password);
     // Allocate output buffer
     hash = new byte[NTHashNumBytes];
     return RtlCalculateNtOwfPassword(ref unicodePassword, hash);
 }
Пример #2
0
 internal static Win32ErrorCode WNetAddConnection2(ref NetResource netResource, SecureString password, string userName, NetConnectOptions flags)
 {
     using (SafeUnicodeSecureStringPointer passwordPointer = new SafeUnicodeSecureStringPointer(password))
     {
         return(WNetAddConnection2(ref netResource, passwordPointer, userName, flags));
     }
 }
Пример #3
0
        internal static NtStatus RtlCalculateNtOwfPassword(SafeUnicodeSecureStringPointer password, out byte[] hash)
        {
            SecureUnicodeString unicodePassword = new SecureUnicodeString(password);

            // Allocate output buffer
            hash = new byte[NTHashNumBytes];
            return(RtlCalculateNtOwfPassword(ref unicodePassword, hash));
        }
Пример #4
0
 public static byte[] ComputeHash(SecureString password)
 {
     Validator.AssertNotNull(password, "password");
     byte[] hash;
     using(SafeUnicodeSecureStringPointer passwordPtr = new SafeUnicodeSecureStringPointer(password))
     {
         NtStatus result = NativeMethods.RtlCalculateNtOwfPassword(passwordPtr, out hash);
         Validator.AssertSuccess(result);
     }
     return hash;
 }
Пример #5
0
        internal NtStatus DeriveKey(SecureString password, string salt, int iterations, out byte[] key)
        {
            key = new byte[this.KeySize];
            var unicodeSalt = new UnicodeString(salt);

            using (var passwordPointer = new SafeUnicodeSecureStringPointer(password))
            {
                var unicodePassword = new SecureUnicodeString(passwordPointer);
                return(this.KeyDerivationFunction(ref unicodePassword, ref unicodeSalt, iterations, key));
            }
        }
Пример #6
0
 public SecureUnicodeString(SafeUnicodeSecureStringPointer passwordPtr)
 {
     this.Buffer = passwordPtr;
     if (passwordPtr == null)
     {
         this.Length = 0;
         this.MaximumLength = 0;
     }
     else if (passwordPtr.NumBytesTotal >= ushort.MaxValue)
     {
         throw new ArgumentOutOfRangeException("passwordPtr");
     }
     else
     {
         // Length of the unicode string (wchar_t).
         this.Length = (ushort)passwordPtr.NumBytes;
         this.MaximumLength = (ushort)passwordPtr.NumBytesTotal;
     }
 }
Пример #7
0
 public SecureUnicodeString(SafeUnicodeSecureStringPointer passwordPtr)
 {
     this.Buffer = passwordPtr;
     if (passwordPtr == null)
     {
         this.Length        = 0;
         this.MaximumLength = 0;
     }
     else if (passwordPtr.NumBytesTotal >= ushort.MaxValue)
     {
         throw new ArgumentOutOfRangeException("passwordPtr");
     }
     else
     {
         // Length of the unicode string (wchar_t).
         this.Length        = (ushort)passwordPtr.NumBytes;
         this.MaximumLength = (ushort)passwordPtr.NumBytesTotal;
     }
 }
Пример #8
0
        //public static byte[] ComputeHash(SecureString password)
        //{
        //    Validator.AssertNotNull(password, "password");
        //    Validator.AssertMaxLength(password, MaxChars, "password");
        //    int oemPwdBufferLength = Encoding.ASCII.GetMaxByteCount(MaxChars);
        //    byte[] hash;
        //    using (SafeOemStringPointer oemPwdBuffer = SafeOemStringPointer.Allocate(oemPwdBufferLength))
        //    {
        //        using(SafeUnicodeSecureStringPointer unicodePwdBuffer = new SafeUnicodeSecureStringPointer(password))
        //        {

        //            NtStatus result1 = NativeMethods.RtlUpcaseUnicodeToOemN(oemPwdBuffer, (uint)oemPwdBufferLength, unicodePwdBuffer);
        //            Validator.AssertSuccess(result1);
        //        }

        //        NtStatus result2 = NativeMethods.RtlCalculateLmOwfPassword(oemPwdBuffer, out hash);
        //        Validator.AssertSuccess(result2);
        //    }
        //    return hash;
        //}

        public static byte[] ComputeHash(SecureString password)
        {
            Validator.AssertNotNull(password, "password");
            Validator.AssertMaxLength(password, MaxChars, "password");
            int oemPwdBufferLength = Encoding.ASCII.GetMaxByteCount(MaxChars);
            byte[] hash;
            using (SafeOemStringPointer oemPwdBuffer = SafeOemStringPointer.Allocate(oemPwdBufferLength))
            {
                using (SafeUnicodeSecureStringPointer unicodePwdBuffer = new SafeUnicodeSecureStringPointer(password))
                {

                    SecureUnicodeString unicodePwd = new SecureUnicodeString(unicodePwdBuffer);
                    OemString oemPwd = new OemString(oemPwdBuffer);
                    NtStatus result1 = NativeMethods.RtlUpcaseUnicodeStringToOemString(oemPwd, unicodePwd);
                    Validator.AssertSuccess(result1);
                }

                NtStatus result2 = NativeMethods.RtlCalculateLmOwfPassword(oemPwdBuffer, out hash);
                Validator.AssertSuccess(result2);
            }
            return hash;
        }
Пример #9
0
 private static extern Win32ErrorCode WNetAddConnection2([In] ref NetResource netResource, [In] SafeUnicodeSecureStringPointer password, [In][MarshalAs(UnmanagedType.LPWStr)] string userName, NetConnectOptions flags);
Пример #10
0
 internal static Win32ErrorCode WNetAddConnection2(ref NetResource netResource, SecureString password, string userName, NetConnectOptions flags)
 {
     using (SafeUnicodeSecureStringPointer passwordPointer = new SafeUnicodeSecureStringPointer(password))
     {
         return WNetAddConnection2(ref netResource, passwordPointer, userName, flags);
     }
 }