code: private PrivateKey loadPrivateKey(File privateKeyFile)
      throws Exception
      {
      // Load the key file.
      System.out.println("Loading private key from "
                 + privateKeyFile
                 + ", using " + providerClassName
                 + " as the private key loading provider");
          FileInputStream privateKeyInputStream = null;
          byte[] keyBytes;
          
          try
          {
              privateKeyInputStream = new FileInputStream(privateKeyFile);
              keyBytes = new byte[(int) privateKeyFile.length()];
              privateKeyInputStream.read(keyBytes);
          }
          finally
          {
              IO.close(privateKeyInputStream);
          }
      
          // Dynamically register the Bouncy Castle provider for RSA
      // support.
      Class providerClass = Loader.loadClass(this.getClass(),providerClassName);
      Provider provider = (Provider)providerClass.newInstance();
      Security.insertProviderAt(provider, 1);
      try {
          // Load the private key
          PKCS8EncodedKeySpec privateKeySpec
          = new PKCS8EncodedKeySpec(keyBytes);
          KeyFactory keyFactory
          = KeyFactory.getInstance("RSA");
          PrivateKey privateKey
          = keyFactory.generatePrivate(privateKeySpec);
          
          System.out.println("Loaded " + privateKey.getAlgorithm()
                     + " " + privateKey.getFormat()
                     + " private key.");
          return privateKey;
      } finally {
          // Dynamically deinstall the RSA provider 
          Security.removeProvider(provider.getName());
      }
      }
docs: Load an RSA private key from the given File
  @param privateKeyFile String name of file to load the key from
  @return PrivateKey loaded from the file
  @throws Exception if there are problems with loading the key.