Nobel prize-winning author Nadine Gordimer has spoken out against her government's controversial new secrecy legislation, suggesting it is a move back towards the harsh censorship that existed under apartheid.

In an article written for the ObserverGordimer said freedom of expression had been "struck out as a danger to the state", under the harsh Protection of State Information Bill, which may become law in South Africa by the end of the year. Leading commentators, editors and opposition parties dubbed the day the bill was passed in the South African parliament last week "Black Tuesday".

The bill bans the publication of classified documents – even if the information could be in the public interest – and allows the government to class almost any category of information as secret. Anyone involved in whistleblowing or any journalist or editor involved in publishing such information could face 25 years in prison. The bill is also seen as a way of the government controlling how it is represented, and there are worries that its provisions are so all-encompassing that it could even curtail freedom of expression in literature.

Gordimer argues that the attack on media freedom is an attack on everyone's "right to know and think", which would affect the work of all writers. ANC politicians have said the laws are necessary because the country is under threat from "spies" and foreign invasion, while state security minister Siyabonga Cwele has claimed that groups opposing the bill were "local proxies of foreign spies".

President Jacob Zuma has been accused of having too close a relationship with his country's security services and of conducting a personal vendetta against South African media who have been putting his party and his leadership under ever increasing scrutiny. Raymond Louw, veteran former anti-apartheid editor and media activist, has told reporters the law is a betrayal of the ANC's commitment to press freedom.

"The intention of this bill is to stop the media from disclosing corruption, malpractice and misgovernance, and inefficiencies," he said. "It is a betrayal of the commitment to a free press and the constitutional commitment to a free press because it is so wide-ranging. And it is not reasonable for them to want to cover up secrets beyond those which are absolutely necessary for protection of national security."

Gordimer's attack is likely to embarrass the ANC ruling party, especially those who are already uncomfortable with the bill, which has two further stages to go through before it is signed into law by Zuma.

The author pours scorn on the idea that South Africa might be under any kind of threat from outside forces, saying: "Is Cuba going to send an invasive force to bring to power our small communist party?"

She writes that the bill would not just affect the press but also poets, novelists and playwrights: "Workers in all literary modes will be subject to the bill through our fictional characters' actions and opinions, alive in our books."

The author has long links with the struggle against black oppression. She had three books banned under the infamous apartheid regime's censorship laws, along with an anthology of poetry by black South African writers that she collected and had published.

Gordimer was born in Gauteng, South Africa, in 1923 to immigrant European parents. She was called one of the great "guerrillas of the imagination" by the poet Seamus Heaney, and a "magnificent epic writer" by the Nobel committee, and is a hugely respected figure involved in charitable and anti-censorship projects.

She became active in the then banned South African National Congress after the Sharpeville massacre, and was one of the first people Nelson Mandela asked to see when he was released in 1990. When her west Johannesburg home was raided by violent robbers in 2006, it sparked national outrage.