protected override void ProcessRecord() { // TODO: Extract as resource WriteVerbose("Calculating LM hash."); try { byte[] hashBytes = LMHash.ComputeHash(this.Password); string hashHex = hashBytes.ToHex(); this.WriteObject(hashHex); } catch (ArgumentException ex) { ErrorRecord error = new ErrorRecord(ex, "Error1", ErrorCategory.InvalidArgument, this.Password); this.WriteError(error); } catch (Win32Exception ex) { // TODO: Handle password length. ErrorCategory category = ((Win32ErrorCode)ex.NativeErrorCode).ToPSCategory(); ErrorRecord error = new ErrorRecord(ex, "Error2", category, this.Password); // Allow the processing to continue on this error: this.WriteError(error); } catch (Exception ex) { ErrorRecord error = new ErrorRecord(ex, "Error3", ErrorCategory.NotSpecified, this.Password); this.WriteError(error); } }
public void LMHash_TestVector1() { SecureString password = "******".ToSecureString(); string result = LMHash.ComputeHash(password).ToHex(true); string expected = "727E3576618FA1754A3B108F3FA6CB6D"; Assert.AreEqual(expected, result); }
public void LMHash_EmptyInput() { SecureString password = string.Empty.ToSecureString(); string result = LMHash.ComputeHash(password).ToHex(true); string expected = "AAD3B435B51404EEAAD3B435B51404EE"; Assert.AreEqual(expected, result); }
public void LMHash_InputWithDiacriticalMarks() { // Taken from AD, so the correctness of the expected result is guaranteed SecureString password = "******".ToSecureString(); string result = LMHash.ComputeHash(password).ToHex(false); string expected = "f9393d97e7a1873caad3b435b51404ee"; Assert.AreEqual(expected, result); }
public void LMHash_UnicodeInput() { // Taken from AD, so the correctness of the expected result is guaranteed SecureString password = "******".ToSecureString(); string result = LMHash.ComputeHash(password).ToHex(false); string expected = "5a5503d0e85f58abaad3b435b51404ee"; Assert.AreEqual(expected, result); }
/// <summary> /// Computes an NT hash value with a password LMOWFv1 /// </summary> /// <param name="password">A password to compute hash</param> /// <exception cref="ArgumentNullException">Raised if password is null</exception> /// <returns>An LM hash value.</returns> public static byte[] GetHashWithLMOWFv1(string password) { if (password == null) { // Will be changed to StackSdkException after StackSdkException class is updated. throw new ArgumentNullException("password"); } LMHash lmHashAlg = LMHashManaged.Create(); return(lmHashAlg.ComputeHash(Encoding.ASCII.GetBytes(password))); }
public void LMHash_LongInput() { // LM Hash history contains aad3b435b51404eeaad3b435b51404ee, hash of empty string SecureString password = "******".ToSecureString(); string result = LMHash.ComputeHash(password).ToHex(true); }
public void LMHash_NullInput() { LMHash.ComputeHash(null); }