Code example for KeyFactory

Methods: generatePublic, getKeySpec, translateKey

0
                  public String getAlgorithm() { return "DSA"; }
                  public byte[] getEncoded()   { return enc2; }
                  public String getFormat()    { return "X.509"; }
              }; 
 
        X509EncodedKeySpec ks = kf.getKeySpec(pubKey, X509EncodedKeySpec.class);
 
        pubKey = (DSAPublicKey) kf.generatePublic((KeySpec)ks);
        pubKey = (DSAPublicKey) kf.translateKey( (Key)pubKey );
 
        String alg = pubKey.getAlgorithm();
        assertNotNull(alg);
        assertFalse("X.509".equals(alg));
    } 
 
 
    /** 
     * A compatibility with RI test. 
     * The test against the "translateKey(Key)" method. 
     * It checks out that  
     * if a key encoding in a DSAPrivateKey argument has correct ASN1 structure