Example #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);
 }
Example #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));
     }
 }
Example #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));
        }
Example #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;
 }
Example #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));
            }
        }
 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;
     }
 }
 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;
     }
 }
Example #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;
        }
Example #9
0
 private static extern Win32ErrorCode WNetAddConnection2([In] ref NetResource netResource, [In] SafeUnicodeSecureStringPointer password, [In][MarshalAs(UnmanagedType.LPWStr)] string userName, NetConnectOptions flags);
Example #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);
     }
 }