The patented RSA algorithm (public key exchange) was independently developed by Rivest, Shamir and Adleman. However the algorithm had been found much earlier and secretly by Ellis and Cocks. This was eventually revealed, but the RSA patent remained valid until it expired in 2000.
The prior art must be known to the patent office before the patent is granted to stop a patent from being granted. What the patent office grants will obviously depend on what they know. To invalidate a patent later, what counts is the date when the "secret" prior art became public knowledge. So if the patent office could have theoretically found the prior art, then you have a chance.
In the case of RSA, that wasn't the case. It is clearly documented that Ellis and Cocks invented the algorithm earlier, and it was even shared with US intelligence, but it was not known to the public when RSA got their patent.
For your semi-secret prior art: If I try to get a patent, could you write to the patent officer "there's a small village named XYZ in Siberia, and in their public library there's a book titled "Secrets of ABC" that has prior art to gnasher's patent" before I get my patent? So it's public, but so obscure that nobody would ever find it in practice, but the patent officer could book a flight to Siberia, a bus to the village, and he could enter the library and find the book with the prior art?