//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; }
internal static NtStatus RtlUpcaseUnicodeStringToOemString(OemString destinationString, SecureUnicodeString sourceString) { return(RtlUpcaseUnicodeStringToOemString(ref destinationString, ref sourceString, false)); }
private static extern NtStatus RtlUpcaseUnicodeStringToOemString([In, Out] ref OemString destinationString, [In] ref SecureUnicodeString sourceString, [MarshalAs(UnmanagedType.Bool)] bool allocateDestinationString);
internal static NtStatus RtlUpcaseUnicodeStringToOemString(OemString destinationString, SecureUnicodeString sourceString) { return RtlUpcaseUnicodeStringToOemString(ref destinationString, ref sourceString, false); }