if (k instanceof DSAKey) { System.out.println("key is DSA"); System.out.println("P value is " + ((DSAKey) k).getParams().getP()); } else System.out.println("key is not DSA");