title: Exception in thread "main" java.io.IOException: toDerInputStream rejects tag type 53 when accessing google spreadsheets
body: <p>Trying to access google spreadsheets. However, the above error is getting displayed. I have created the .p12 file using the client id from developers.google.com. Please let me know what is the issue. Complete error is as follows:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.io.IOException: toDerInputStream
    rejects tag type 53   at
    sun.security.util.DerValue.toDerInputStream(Unknown Source)   at
    sun.security.pkcs12.PKCS12KeyStore.engineLoad(Unknown Source)     at
    java.security.KeyStore.load(Unknown Source)   at
    com.google.api.client.util.SecurityUtils.loadKeyStore(SecurityUtils.java:82)
      at
    com.google.api.client.util.SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.java:115)
      at
    com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder.setServiceAccountPrivateKeyFromP12File(GoogleCredential.java:670)
      at testExcelAuth.testExcelAuth.main(testExcelAuth.java:27)</p>
  </blockquote>
  
  <p>Given below is the code I am using:</p>
  
  <pre><code>package testExcelAuth;
  
  import java.io.File;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.List;
  
  import com.google.gdata.client.spreadsheet.SpreadsheetService;
  import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
  import com.google.api.client.http.javanet.NetHttpTransport;
  import com.google.api.client.json.jackson2.JacksonFactory;
  import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
  import com.google.gdata.data.spreadsheet.SpreadsheetFeed;
  import com.google.api.services.drive.DriveScopes;
  
  
  public class testExcelAuth {
  
    public static void main(String[] args) throws Exception {
      ArrayList scopes = new ArrayList();
      scopes.add(0, DriveScopes.DRIVE);
      scopes.add(1, "https://spreadsheets.google.com/feeds");
      GoogleCredential credential = new GoogleCredential.Builder()
          .setTransport(new NetHttpTransport())
          .setJsonFactory(new JacksonFactory())
          .setServiceAccountId("rkulkarni@securet.in")
          .setServiceAccountPrivateKeyFromP12File(newFile(
         ".\\src\\testExcelAuth\\key.p12"))
          .setServiceAccountScopes(scopes).build();
  
      credential.refreshToken();
  
      SpreadsheetService service = new SpreadsheetService("tmp");
      service.setOAuth2Credentials(credential);
  
      // Define the URL to request. This should never change.
      URL SPREADSHEET_FEED_URL = new URL(
          "https://spreadsheets.google.com/feeds/spreadsheets/private/full");
  
      // Make a request to the API and get all spreadsheets.
      SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
          SpreadsheetFeed.class);
      List&lt;SpreadsheetEntry&gt; spreadsheets = feed.getEntries();
  
      // Iterate through all of the spreadsheets returned
      int i = 0;
      for (SpreadsheetEntry spreadsheet : spreadsheets) {
        ++i;
        System.out.println(spreadsheet.getId());
      }
      System.out.println("Done " + i);   
    }
  }
  </code></pre>