code: private static byte[] readBytes(BufferedReader reader, String endMarker) throws IOException
      {
          String          line = null;
          StringBuilder   buf = new StringBuilder();
  
          while ((line = reader.readLine()) != null)
          {
              if (line.contains(endMarker)) {
                  return Base64.getDecoder().decode(buf.toString());
              }
  
              buf.append(line.trim());        
          }
  
          throw new IOException("Invalid PEM file: No end marker");
      }
docs: Read the lines between BEGIN and END marker and convert
  the Base64 encoded content into binary byte array.
  
  @return DER encoded octet stream
  @throws IOException