throw new IllegalArgumentException("Wrong key type");
throw new InvalidParameterException("Wrong key type");
  public byte[] encodePrivateKey(PrivateKey key)  {    if (! (key instanceof DSSPrivateKey))      throw new IllegalArgumentException("Wrong key type");    DERValue derVersion = new DERValue(DER.INTEGER, BigInteger.ZERO);    DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, DSA_ALG_OID);    DSSPrivateKey pk = (DSSPrivateKey) key;    BigInteger p = pk.getParams().getP();    BigInteger q = pk.getParams().getQ();    BigInteger g = pk.getParams().getG();    BigInteger x = pk.getX();    ArrayList params = new ArrayList(3);    params.add(new DERValue(DER.INTEGER, p));    params.add(new DERValue(DER.INTEGER, q));    params.add(new DERValue(DER.INTEGER, g));    DERValue derParams = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, params);    ArrayList algorithmID = new ArrayList(2);    algorithmID.add(derOID);    algorithmID.add(derParams);    DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,                                           algorithmID);    DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, Util.trim(x));    ArrayList pki = new ArrayList(3);    pki.add(derVersion);    pki.add(derAlgorithmID);    pki.add(derPrivateKey);    DERValue derPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, pki);    byte[] result;    ByteArrayOutputStream baos = new ByteArrayOutputStream();    try      {        DERWriter.write(baos, derPKI);        result = baos.toByteArray();      }    catch (IOException e)      {        InvalidParameterException y = new InvalidParameterException();        y.initCause(e);        throw y;      }    return result;  }