Supports reading any PEM stream that contains Base64 encoded content stored inside
"-----BEGIN ...-----" and "-----END ...-----" tags. Each call to #readNextSection() parses the next section in the PEM file. If you need a section of a certain
title use #readNextSection(String), for example readNextSection("PRIVATE KEY").
To ensure that the stream is closed properly, call #close() in a finally block.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class PemReader (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.PemReader)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.PemReader)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.PemReader)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.PemReader)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.PemReader)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.PemReader)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.PemReader) \n\n public final class PemReader\n\n[Beta](/java/docs/reference/google-http-client/latest/com.google.api.client.util.Beta) \n\nPEM file reader.\n\nSupports reading any PEM stream that contains Base64 encoded content stored inside `\n\"-----BEGIN ...-----\"` and `\"-----END ...-----\"` tags. Each call to [#readNextSection()](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader#com_google_api_client_util_PemReader_readNextSection__) parses the next section in the PEM file. If you need a section of a certain\ntitle use [#readNextSection(String)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader#com_google_api_client_util_PemReader_readNextSection_java_lang_String_), for example `readNextSection(\"PRIVATE KEY\")`.\nTo ensure that the stream is closed properly, call [#close()](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader#com_google_api_client_util_PemReader_close__) in a finally block.\n\nAs a convenience, use [#readFirstSectionAndClose(Reader)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader#com_google_api_client_util_PemReader_readFirstSectionAndClose_java_io_Reader_) or [#readFirstSectionAndClose(Reader, String)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader#com_google_api_client_util_PemReader_readFirstSectionAndClose_java_io_Reader_java_lang_String_) for the common case of only a single section in a PEM\nfile (or only a single section of a given title).\n\nLimitations:\n\n\n- Assumes the PEM file section content is not encrypted and cannot handle the case of any headers inside the BEGIN and END tag.\n- It also ignores any attributes associated with any PEM file section. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e PemReader \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### readFirstSectionAndClose(Reader reader)\n\n public static PemReader.Section readFirstSectionAndClose(Reader reader)\n\nReads the first section in the PEM file, and then closes the reader.\n\n### readFirstSectionAndClose(Reader reader, String titleToLookFor)\n\n public static PemReader.Section readFirstSectionAndClose(Reader reader, String titleToLookFor)\n\nReads the first section in the PEM file, optionally based on a title to look for, and then\ncloses the reader.\n\nConstructors\n------------\n\n### PemReader(Reader reader)\n\n public PemReader(Reader reader)\n\nMethods\n-------\n\n### close()\n\n public void close()\n\nCloses the reader.\n\nTo ensure that the stream is closed properly, call [#close()](/java/docs/reference/google-http-client/latest/com.google.api.client.util.PemReader#com_google_api_client_util_PemReader_close__) in a finally block.\n\n### readNextSection()\n\n public PemReader.Section readNextSection()\n\nReads the next section in the PEM file or `null` for end of file.\n\n### readNextSection(String titleToLookFor)\n\n public PemReader.Section readNextSection(String titleToLookFor)\n\nReads the next section in the PEM file, optionally based on a title to look for."]]