Code example for DSAParams

Methods: getG, getP, getQ

0
         
        KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
        gen.initialize((DSAParameterSpec) param);
        DSAKey key = null;
         
        // Case 1: check private key 
        key = (DSAKey) gen.generateKeyPair().getPrivate();
        assertDSAParamsEquals(param, key.getParams());
         
        // Case 2: check public key 
        key = (DSAKey) gen.generateKeyPair().getPublic();                
        assertDSAParamsEquals(param, key.getParams());
    } 
     
    private void assertDSAParamsEquals(DSAParams expected, DSAParams actual) {
        assertEquals("P differ", expected.getP(), actual.getP());
        assertEquals("Q differ", expected.getQ(), actual.getQ());
        assertEquals("G differ", expected.getG(), actual.getG());
    } 
}