Code example for Key

Methods: getEncodedgetFormat

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());
       } 
       else if (spec.isAssignableFrom(RSAPublicKeySpec.class) && key instanceof RSAPublicKey)
       { 
            RSAPublicKey    k = (RSAPublicKey)key;
 
            return new RSAPublicKeySpec(k.getModulus(), k.getPublicExponent());
       } 
       else if (spec.isAssignableFrom(RSAPrivateKeySpec.class) && key instanceof RSAPrivateKey)
Stop searching for code, let great code find you!  Add Codota to your java IDE