protected <T extends KeySpec>T engineGetKeySpec(Key key,Class<T> keySpec) throws InvalidKeySpecException {
  DSAParams params;
  try {
    if (key instanceof java.security.interfaces.DSAPublicKey) {
      Class<?> dsaPubKeySpec=Class.forName("java.security.spec.DSAPublicKeySpec");
      Class<?> x509KeySpec=Class.forName("java.security.spec.X509EncodedKeySpec");
      if (dsaPubKeySpec.isAssignableFrom(keySpec)) {
        java.security.interfaces.DSAPublicKey dsaPubKey=(java.security.interfaces.DSAPublicKey)key;
        params=dsaPubKey.getParams();
        return keySpec.cast(new DSAPublicKeySpec(dsaPubKey.getY(),params.getP(),params.getQ(),params.getG()));
      }
 else       if (x509KeySpec.isAssignableFrom(keySpec)) {
        return keySpec.cast(new X509EncodedKeySpec(key.getEncoded()));
      }
 else {
        throw new InvalidKeySpecException("Inappropriate key specification");
      }
    }
 else     if (key instanceof java.security.interfaces.DSAPrivateKey) {
      Class<?> dsaPrivKeySpec=Class.forName("java.security.spec.DSAPrivateKeySpec");
      Class<?> pkcs8KeySpec=Class.forName("java.security.spec.PKCS8EncodedKeySpec");
      if (dsaPrivKeySpec.isAssignableFrom(keySpec)) {
        java.security.interfaces.DSAPrivateKey dsaPrivKey=(java.security.interfaces.DSAPrivateKey)key;
        params=dsaPrivKey.getParams();
        return keySpec.cast(new DSAPrivateKeySpec(dsaPrivKey.getX(),params.getP(),params.getQ(),params.getG()));
      }
 else       if (pkcs8KeySpec.isAssignableFrom(keySpec)) {
        return keySpec.cast(new PKCS8EncodedKeySpec(key.getEncoded()));
      }
 else {
        throw new InvalidKeySpecException("Inappropriate key specification");
      }
    }
 else {
      throw new InvalidKeySpecException("Inappropriate key type");
    }
  }
 catch (  ClassNotFoundException e) {
    throw new InvalidKeySpecException("Unsupported key specification: " + e.getMessage());
  }
}

protected < T extends KeySpec > T engineGetKeySpec ( Key key , Class < T > keySpec ) throws InvalidKeySpecException { DSAParams params ; try { if ( key instanceof java . security . interfaces . DSAPublicKey ) { Class < ? > dsaPubKeySpec = Class . forName ( "java.security.spec.DSAPublicKeySpec" ) ; Class < ? > x509KeySpec = Class . forName ( "java.security.spec.X509EncodedKeySpec" ) ; if ( dsaPubKeySpec . isAssignableFrom ( keySpec ) ) { java . security . interfaces . DSAPublicKey dsaPubKey = ( java . security . interfaces . DSAPublicKey ) key ; params = dsaPubKey . getParams ( ) ; return keySpec . cast ( new DSAPublicKeySpec ( dsaPubKey . getY ( ) , params . getP ( ) , params . getQ ( ) , params . getG ( ) ) ) ; } else if ( x509KeySpec . isAssignableFrom ( keySpec ) ) { return keySpec . cast ( new X509EncodedKeySpec ( key . getEncoded ( ) ) ) ; } else { throw new InvalidKeySpecException ( "Inappropriate key specification" ) ; } } else if ( key instanceof java . security . interfaces . DSAPrivateKey ) { Class < ? > dsaPrivKeySpec = Class . forName ( "java.security.spec.DSAPrivateKeySpec" ) ; Class < ? > pkcs8KeySpec = Class . forName ( "java.security.spec.PKCS8EncodedKeySpec" ) ; if ( dsaPrivKeySpec . isAssignableFrom ( keySpec ) ) { java . security . interfaces . DSAPrivateKey dsaPrivKey = ( java . security . interfaces . DSAPrivateKey ) key ; params = dsaPrivKey . getParams ( ) ; return keySpec . cast ( new DSAPrivateKeySpec ( dsaPrivKey . getX ( ) , params . getP ( ) , params . getQ ( ) , params . getG ( ) ) ) ; } else if ( pkcs8KeySpec . isAssignableFrom ( keySpec ) ) { return keySpec . cast ( new PKCS8EncodedKeySpec ( key . getEncoded ( ) ) ) ; } else { throw new InvalidKeySpecException ( "Inappropriate key specification" ) ; } } else { throw new InvalidKeySpecException ( "Inappropriate key type" ) ; } } catch ( ClassNotFoundException e ) { throw new InvalidKeySpecException ( "Unsupported key specification: " + e . getMessage ( ) ) ; } }
returns a specification ( key material ) of the given key object in the requested format .
