public bool ValidateNewPasswordEncryptedWithOldNt(_SAMPR_ENCRYPTED_USER_PASSWORD target) { _SAMPR_ENCRYPTED_USER_PASSWORD expected = GetNewPasswordEncryptedWithOldNt(); bool isSame = ObjectUtility.DeepCompare(expected, target); return(isSame); }
/// <summary> /// Gets a password encrypted with session key. /// </summary> /// <param name="password">The password to be encrypted</param> /// <param name="sessionKey">The session key used for encryption.</param> /// <exception cref="ArgumentNullException">Raised when session key is null</exception> /// <returns>The encrypted password.</returns> private _SAMPR_ENCRYPTED_USER_PASSWORD GetPasswordEncryptedWithSessionKey( string password, byte[] sessionKey) { if (sessionKey == null) { throw new ArgumentNullException("sessionKey"); } _SAMPR_ENCRYPTED_USER_PASSWORD encryptedPwd = new _SAMPR_ENCRYPTED_USER_PASSWORD(); encryptedPwd.Buffer = new byte[encryptedPwdSize + pwdLenSize]; // Get new password bytes byte[] passwordBytes = Encoding.Unicode.GetBytes(password); // Copy password bytes to the tail of the encryptedPwdSize bytes of buffer Array.Copy(passwordBytes, 0, encryptedPwd.Buffer, encryptedPwdSize - passwordBytes.Length, passwordBytes.Length); // Set password length for the last pwdLenSize bytes of the (encryptedPwdSize + pwdLenSize) bytes byte[] lengthBytes = BitConverter.GetBytes(passwordBytes.Length); Array.Copy(lengthBytes, 0, encryptedPwd.Buffer, encryptedPwdSize, pwdLenSize); // Do RC4 encryption encryptedPwd.Buffer = RC4Encrypt(encryptedPwd.Buffer, 0, encryptedPwd.Buffer.Length, sessionKey); return(encryptedPwd); }
/// <summary> /// Validate the existing password encrypted with session key. /// </summary> /// <param name="sessionKey">The session key used for encryption.</param> /// <param name="target"> the target to be validate</param> /// <returns>validate result</returns> public bool ValidateOldPasswordEncryptedWithSessionKey(byte[] sessionKey, _SAMPR_ENCRYPTED_USER_PASSWORD target) { _SAMPR_ENCRYPTED_USER_PASSWORD expected = GetOldPasswordEncryptedWithSessionKey(sessionKey); bool isSame = ObjectUtility.DeepCompare(expected, target); return(isSame); }
public _SAMPR_ENCRYPTED_USER_PASSWORD GetNewPasswordEncryptedWithOldNt() { _SAMPR_ENCRYPTED_USER_PASSWORD encryptedPwd = new _SAMPR_ENCRYPTED_USER_PASSWORD(); encryptedPwd.Buffer = new byte[encryptedPwdSize + pwdLenSize]; // Get new password bytes byte[] newPwdBytes = Encoding.Unicode.GetBytes(newPwd); // Copy password bytes to the tail of the encryptedPwdSize bytes of buffer Array.Copy(newPwdBytes, 0, encryptedPwd.Buffer, encryptedPwdSize - newPwdBytes.Length, newPwdBytes.Length); // Set password length for the last pwdLenSize bytes of the (encryptedPwdSize + pwdLenSize) bytes byte[] lengthBytes = BitConverter.GetBytes(newPwdBytes.Length); Array.Copy(lengthBytes, 0, encryptedPwd.Buffer, encryptedPwdSize, pwdLenSize); // Get NT hash of existing password byte[] oldNtowf = GetHashWithNTOWFv1(existingPwd); // Do RC4 encryption encryptedPwd.Buffer = RC4Encrypt(encryptedPwd.Buffer, 0, encryptedPwd.Buffer.Length, oldNtowf); return(encryptedPwd); }
public _SAMPR_ENCRYPTED_USER_PASSWORD GetNewPasswordEncryptedWithOldLm(PasswordType passwordType) { _SAMPR_ENCRYPTED_USER_PASSWORD encryptedPwd = new _SAMPR_ENCRYPTED_USER_PASSWORD(); encryptedPwd.Buffer = new byte[encryptedPwdSize + pwdLenSize]; Encoding targetEncoding; if (passwordType == PasswordType.Oem) { // Windows OEM encoding is ASCII targetEncoding = Encoding.ASCII; } else if (passwordType == PasswordType.Unicode) { targetEncoding = Encoding.Unicode; } else { throw new InvalidOperationException("Invalid password type"); } // Get new password bytes byte[] newPwdBytes = targetEncoding.GetBytes(newPwd); // Copy password bytes to the tail of the encryptedPwdSize bytes of buffer Array.Copy(newPwdBytes, 0, encryptedPwd.Buffer, encryptedPwdSize - newPwdBytes.Length, newPwdBytes.Length); // Set password length for the last pwdLenSize bytes of the (encryptedPwdSize + pwdLenSize) bytes byte[] lengthBytes = BitConverter.GetBytes(newPwdBytes.Length); Array.Copy(lengthBytes, 0, encryptedPwd.Buffer, encryptedPwdSize, lengthBytes.Length); // Get LM hash of existing password byte[] oldLmowf = GetHashWithLMOWFv1(existingPwd); // Do RC4 encryption encryptedPwd.Buffer = RC4Encrypt(encryptedPwd.Buffer, 0, encryptedPwd.Buffer.Length, oldLmowf); return(encryptedPwd); }