code: private static byte[] getDecodedPEMObject(BufferedReader reader) throws IOException {
          String line;
          StringBuffer buf = new StringBuffer();
          while ((line = reader.readLine()) != null) {
              if (line.indexOf("--END") != -1) { // found end
                  return Base64.decode(buf.toString().getBytes());
              } else {
                  buf.append(line);
              }
          }
          throw new EOFException("Missing PEM end footer");
      }
docs: Reads Base64 encoded data from the stream and returns its decoded value. The reading continues until
  the "END" string is found in the data. Otherwise, returns null.