protected <T extends KeySpec>T engineGetKeySpec(Key key,Class<T> keySpec) throws InvalidKeySpecException {
  BigInteger p, q, g, x, y;
  if (key != null) {
    if (keySpec == null) {
      throw new NullPointerException("keySpec == null");
    }
    if (key instanceof DSAPrivateKey) {
      DSAPrivateKey privateKey=(DSAPrivateKey)key;
      if (keySpec.equals(DSAPrivateKeySpec.class)) {
        x=privateKey.getX();
        DSAParams params=privateKey.getParams();
        p=params.getP();
        q=params.getQ();
        g=params.getG();
        return (T)(new DSAPrivateKeySpec(x,p,q,g));
      }
      if (keySpec.equals(PKCS8EncodedKeySpec.class)) {
        return (T)(new PKCS8EncodedKeySpec(key.getEncoded()));
      }
      throw new InvalidKeySpecException("'keySpec' is neither DSAPrivateKeySpec nor PKCS8EncodedKeySpec");
    }
    if (key instanceof DSAPublicKey) {
      DSAPublicKey publicKey=(DSAPublicKey)key;
      if (keySpec.equals(DSAPublicKeySpec.class)) {
        y=publicKey.getY();
        DSAParams params=publicKey.getParams();
        p=params.getP();
        q=params.getQ();
        g=params.getG();
        return (T)(new DSAPublicKeySpec(y,p,q,g));
      }
      if (keySpec.equals(X509EncodedKeySpec.class)) {
        return (T)(new X509EncodedKeySpec(key.getEncoded()));
      }
      throw new InvalidKeySpecException("'keySpec' is neither DSAPublicKeySpec nor X509EncodedKeySpec");
    }
  }
  throw new InvalidKeySpecException("'key' is neither DSAPublicKey nor DSAPrivateKey");
}

protected < T extends KeySpec > T engineGetKeySpec ( Key key , Class < T > keySpec ) throws InvalidKeySpecException { BigInteger p , q , g , x , y ; if ( key != null ) { if ( keySpec == null ) { throw new NullPointerException ( "keySpec == null" ) ; } if ( key instanceof DSAPrivateKey ) { DSAPrivateKey privateKey = ( DSAPrivateKey ) key ; if ( keySpec . equals ( DSAPrivateKeySpec . class ) ) { x = privateKey . getX ( ) ; DSAParams params = privateKey . getParams ( ) ; p = params . getP ( ) ; q = params . getQ ( ) ; g = params . getG ( ) ; return ( T ) ( new DSAPrivateKeySpec ( x , p , q , g ) ) ; } if ( keySpec . equals ( PKCS8EncodedKeySpec . class ) ) { return ( T ) ( new PKCS8EncodedKeySpec ( key . getEncoded ( ) ) ) ; } throw new InvalidKeySpecException ( "'keySpec' is neither DSAPrivateKeySpec nor PKCS8EncodedKeySpec" ) ; } if ( key instanceof DSAPublicKey ) { DSAPublicKey publicKey = ( DSAPublicKey ) key ; if ( keySpec . equals ( DSAPublicKeySpec . class ) ) { y = publicKey . getY ( ) ; DSAParams params = publicKey . getParams ( ) ; p = params . getP ( ) ; q = params . getQ ( ) ; g = params . getG ( ) ; return ( T ) ( new DSAPublicKeySpec ( y , p , q , g ) ) ; } if ( keySpec . equals ( X509EncodedKeySpec . class ) ) { return ( T ) ( new X509EncodedKeySpec ( key . getEncoded ( ) ) ) ; } throw new InvalidKeySpecException ( "'keySpec' is neither DSAPublicKeySpec nor X509EncodedKeySpec" ) ; } } throw new InvalidKeySpecException ( "'key' is neither DSAPublicKey nor DSAPrivateKey" ) ; }
this method returns a specification for the supplied key . the specification will be returned in the form of an object of the type specified by keyspec .
