Code example for Key

Methods: getEncoded, getFormat

0
    protected KeySpec engineGetKeySpec(
        Key key,
        Class spec)
        throws InvalidKeySpecException 
    { 
        if (spec.isAssignableFrom(PKCS8EncodedKeySpec.class) && key.getFormat().equals("PKCS#8"))
        { 
            return new PKCS8EncodedKeySpec(key.getEncoded());
        } 
        else if (spec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
        { 
            return new X509EncodedKeySpec(key.getEncoded());
        } 
 
        throw new InvalidKeySpecException("not implemented yet " + key + " " + spec);
    } 
}