Пример #1
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;
        }
Пример #2
0
 internal static NtStatus RtlUpcaseUnicodeStringToOemString(OemString destinationString, SecureUnicodeString sourceString)
 {
     return(RtlUpcaseUnicodeStringToOemString(ref destinationString, ref sourceString, false));
 }
Пример #3
0
 private static extern NtStatus RtlUpcaseUnicodeStringToOemString([In, Out] ref OemString destinationString, [In] ref SecureUnicodeString sourceString, [MarshalAs(UnmanagedType.Bool)] bool allocateDestinationString);
Пример #4
0
 internal static NtStatus RtlUpcaseUnicodeStringToOemString(OemString destinationString, SecureUnicodeString sourceString)
 {
     return RtlUpcaseUnicodeStringToOemString(ref destinationString, ref sourceString, false);
 }