return new RSAPrivateKeySpec(k.getModulus(), k.getPrivateExponent());
}
else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey)
{
RSAPrivateCrtKey k = (RSAPrivateCrtKey)key;
return new RSAPrivateCrtKeySpec(
k.getModulus(), k.getPublicExponent(),
k.getPrivateExponent(),
k.getPrimeP(), k.getPrimeQ(),
k.getPrimeExponentP(), k.getPrimeExponentQ(),
k.getCrtCoefficient());
}
else if (spec.isAssignableFrom(DHPrivateKeySpec.class) && key instanceof DHPrivateKey)
{
DHPrivateKey k = (DHPrivateKey)key;
return new DHPrivateKeySpec(k.getX(), k.getParams().getP(), k.getParams().getG());
}
else if (spec.isAssignableFrom(DHPublicKeySpec.class) && key instanceof DHPublicKey)
{
DHPublicKey k = (DHPublicKey)key;
return new DHPublicKeySpec(k.getY(), k.getParams().getP(), k.getParams().getG());
}
else if (spec.isAssignableFrom(java.security.spec.ECPublicKeySpec.class) && key instanceof ECPublicKey)
{
ECPublicKey k = (ECPublicKey)key;
return new java.security.spec.ECPublicKeySpec(k.getW(), k.getParams());
}
else if (spec.isAssignableFrom(java.security.spec.ECPrivateKeySpec.class) && key instanceof ECPrivateKey)
{
ECPrivateKey k = (ECPrivateKey)key;
return new java.security.spec.ECPrivateKeySpec(k.getS(), k.getParams());
}
throw new RuntimeException("not implemented yet " + key + " " + spec);
}