WASHINGTON (AP) _ Secretary of State George Shultz, toning down his rhetoric on Nicaragua, says the United States still finds it useful to maintain diplomatic ties with the Sandinista government.

Shultz, who was flying to Latin America today, testified before a House Foreign Affairs subcommittee Wednesday. He was questioned repeatedly about reports the Reagan administration is looking for a new policy toward the leftist government in Managua, as well as toward the rightist contra guerrillas who are seeking to replace it.

Congress is to vote within the next few months on whether to restore $14 million in secret aid to the contras, who also are receiving military and financial assistance from private sources, and Shultz was asked if the United States might openly provide humanitarian aid to the contras.

Shultz answered only indirectly, but did not rule out the idea.

He said the United States has provided help for refugees and needy persons in Afghanistan, Pakistan and Southeast Asia, where there have been conflicts.

''We have been prepared to provide humanitarian assistance in such situations,'' Shultz said, but made no specific reference to Nicaragua.

Shultz also was asked if any aid was being channeled secretly through Honduras to the contras.

''There is not one dime of U.S. funds going through Honduras to the Nicaraguan contras,'' he said. ''As of now, there is no authority for the executive branch to provide funds for the people fighting for freedom in Nicaragua.''

''I deplore that fact,'' he said, ''but it is a fact.''

The secretary said that even though the Reagan administration dislikes the Sandinista government, it has no plans to close the U.S. embassy in Managua.

''We don't feel we are in a box by virtue of keeping open diplomatic channels,'' he said. ''We think our interests are in maintaining contact.''

Shultz was making further contact with Latin American leaders this week. He was scheduled to be in Uruguay on Friday to attend the inauguration of President Julio Sanguinetti.

In another development Wednesday, Nicaraguan President Daniel Ortega offered to have about 100 Cuban military advisers withdrawn from Nicaragua and to declare an ''indefinite moratorium'' on the acquisition of new weapons systems.

The State Department said it had no immediate comment on Ortega's statement.

Over the past week, Reagan, Shultz and Defense Secretary Caspar Weinberger have waged an intensive campaign in which they said the Sandinistas are operating a totalitarian government under Soviet domination that has put the Nicaraguan people behind the Iron Curtain.

On Wednesday, Shultz said, ''It is not that they have created a totalitarian state, but they are in the process.''

Under questioning from Rep. Peter Kostmayer, D-Pa., Shultz conceded there is still an opposition newspaper published in Nicaragua, although it is censored, and that one-third of the voters in the country voted against the Managua government in the recent elections.

The hearing was marked by a series of emotional confrontations between Shultz and Democratic critics of the administration policy in Nicaragua.

At one point, Kostmayer told Shultz: ''It is you who began the escalation of rhetoric. You have raised the ante. There is a lot of red-baiting going on.''

Shultz replied angrily: ''I am here at the invitation of the committee. If you want to withdraw the invitation, I have lots of other things I can do.''

Said Kostmayer: ''You are the secretary of state. There is nothing I can do about that.''

Earlier, Rep. Ted Weiss, D-N.Y., criticized Shultz' assertion that Nicaragua and Cuba have raised significant amounts of money by indirectly or directly supporting illegal drug sales. Weiss likened Shultz' allegation to tactics used by Sen. Joseph McCarthy during his 1950s investigations of communists in government.

''It is the ultimate perversion to say that an attack on the tactics in Nicaragua is comparable to Sen. McCarthy,'' said Shultz. ''When you compare me to to Sen. McCarthy, I resent it deeply.''

The exchange began when Weiss said the scale of the illegal drug sales in the two countries is ''miniscule'' compared to the amount of heroin, cocaine and marijuana that flow into the United States from American allies.

''It reminds me of the Army-McCarthy hearings of 1954 in which McCarthy, as a way of getting at the Army, went after a young recent law graduate who asked the senator, 'Have you no decency?'''

Weiss was referring to the Senate hearing in which McCarthy was challenged by Army lawyer Joseph Welch.

Weiss said Shultz' reference to illegal drug shipments in Central America and the Caribbean was typical of the administration's policies, which Weiss described as ''of twisting facts, distorting facts and mistating facts.''

Later, as tempers cooled, Weiss said: ''If you concluded from anything I said that I equated you with Sen. McCarthy, then I apologize.''