It was the second time in a week Mr. Trump had used the word “nasty” to describe Ms. Harris. Last Thursday, when the Fox News host Sean Hannity asked him for his thoughts on the senator, Mr. Trump said, “I think she’s got a little bit of a nasty wit, but that might be it.”

Asked Thursday on CNN about why Mr. Trump had chosen to describe her as “nasty,” Ms. Harris chose not to speculate, saying, “God only knows.”

Instead, she drew a broader contrast with the president.

“We have a president of the United States whose primary interest, I think, that has been clear as a result of what we know as a result of the Mueller report, his primary interest has been to obstruct justice,” Ms. Harris said. “My primary interest is to pursue justice. You can call that whatever name you want, but I think that’s what the American people want in a leader.”

Ms. Harris was pointed in her questioning of Mr. Barr at the hearing on Wednesday, which centered on his handling of the special counsel’s report. She displayed her prosecutorial style from her days as San Francisco district attorney and California attorney general, rattling off questions and repeatedly cutting him short. At one point, she prodded Mr. Barr into saying that he had not examined the underlying evidence before deciding not to charge the president with obstruction of justice.

Several Democrats, including Ms. Harris, have called on Mr. Barr to resign. In the interview on Wednesday, Mr. Trump called those demands “ridiculous.”