Ejemplo n.º 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);
 }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
 private static extern NtStatus RtlCalculateNtOwfPassword([In] ref SecureUnicodeString password, [MarshalAs(UnmanagedType.LPArray, SizeConst = NTHashNumBytes), In, Out] byte[] hash);
Ejemplo n.º 6
0
 internal static NtStatus RtlUpcaseUnicodeStringToOemString(OemString destinationString, SecureUnicodeString sourceString)
 {
     return(RtlUpcaseUnicodeStringToOemString(ref destinationString, ref sourceString, false));
 }
Ejemplo n.º 7
0
 private static extern NtStatus RtlUpcaseUnicodeStringToOemString([In, Out] ref OemString destinationString, [In] ref SecureUnicodeString sourceString, [MarshalAs(UnmanagedType.Bool)] bool allocateDestinationString);
Ejemplo n.º 8
0
 internal static NtStatus RtlUpcaseUnicodeStringToOemString(OemString destinationString, SecureUnicodeString sourceString)
 {
     return RtlUpcaseUnicodeStringToOemString(ref destinationString, ref sourceString, false);
 }