/**
   * 从私钥数据文件载入私钥
   * @param file String
   * @return PrivateKey
   * @throws IOException
   * @throws NoSuchAlgorithmException
   * @throws InvalidKeySpecException
   */
  public static PrivateKey loadPrivateKey(String file)throws IOException,NoSuchAlgorithmException,
                                                             InvalidKeySpecException{
    File f = new File(file);
    if( ! f.exists())
      throw new IOException("private key file not found.");
    FileInputStream in = new FileInputStream(f);
    byte[] privateKeyBytes = new byte[file.length()];
    in.read(privateKeyBytes,0,privateKeyBytes.length);
    in.close();
    for(int i=0;i<privateKeyBytes.length;i++)
      System.out.print(Integer.toHexString(privateKeyBytes[i]&0xFF) + " ");
    PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(privateKeyBytes);
    KeyFactory keyf = KeyFactory.getInstance("DSA");
    PrivateKey pKey = keyf.generatePrivate(priPKCS8);
    return pKey;
  }我用的是jdk1.4自带的包