Can I obtain a patent and keep my invention secret?

No. Patents are granted by patent offices in exchange for a full disclosure of the invention. In general, the details of the invention are then published and made available to the public at large.