Code example for KeyFactory

Methods: getKeySpec

0
     * regardless of whether a correct value or null is passed to a Key argument. 
     */ 
    public final void testGetKeySpec01() throws Exception { 
 
        try { 
            kf.getKeySpec( privateKey, DSAPublicKeySpec.class);
            fail("testcase1: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( privateKey, X509EncodedKeySpec.class);
            fail("testcase2: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( null, DSAPublicKeySpec.class);
            fail("testcase3: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( null, X509EncodedKeySpec.class);
            fail("testcase4: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( publicKey, DSAPrivateKeySpec.class);
            fail("testcase5: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( publicKey, PKCS8EncodedKeySpec.class);
            fail("testcase6: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( null, DSAPrivateKeySpec.class);
            fail("testcase7: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
        try { 
            kf.getKeySpec( null, PKCS8EncodedKeySpec.class);
            fail("testcase8: No InvalidKeySpecException");
        } catch (InvalidKeySpecException e) {
        } 
    }