Code example for KeyFactory

Methods: generatePublicgetKeySpec

    public final void testGetKeySpec03() throws Exception { 
        KeySpec ks;
        ks = kf.getKeySpec( publicKey, DSAPublicKeySpec.class);
        checkPublicKeys( (DSAPublicKey) kf.generatePublic((DSAPublicKeySpec) ks) );
        ks = kf.getKeySpec( publicKey, X509EncodedKeySpec.class);
        checkPublicKeys( (DSAPublicKey) kf.generatePublic((X509EncodedKeySpec) ks) );
     * A test against the "getKeySpec(Key, Class)" method. 
     * The test checks out that  
     * 1) a KeySpec returned by the method is being casted to  
          expected "DSAPrivateKeySpec" or "PKCS8EncodedKeySpec", and  
     * 2) DSAPublickey object generated from KeySpec is equal a "privateKey" argument. 
Experience pair programming with AI  Get Codota for Java