InvalidKeySpecException y = new InvalidKeySpecException(); y.initCause(x); throw y;
throw new InvalidKeySpecException(x.getMessage(), x);
  protected PrivateKey engineGeneratePrivate(KeySpec keySpec)      throws InvalidKeySpecException  {    if (keySpec instanceof RSAPrivateCrtKeySpec)      {        RSAPrivateCrtKeySpec spec = (RSAPrivateCrtKeySpec) keySpec;        BigInteger n = spec.getModulus();        BigInteger e = spec.getPublicExponent();        BigInteger d = spec.getPrivateExponent();        BigInteger p = spec.getPrimeP();        BigInteger q = spec.getPrimeQ();        BigInteger dP = spec.getPrimeExponentP();        BigInteger dQ = spec.getPrimeExponentQ();        BigInteger qInv = spec.getCrtCoefficient();        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,                                    n, e, d, p, q, dP, dQ, qInv);      }//    if (keySpec instanceof RSAPrivateKeySpec)//      {//        RSAPrivateKeySpec spec = (RSAPrivateKeySpec) keySpec;//        BigInteger n = spec.getModulus();//        BigInteger d = spec.getPrivateExponent();//        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,//                                    n, null, d, null, null, null, null, null);//      }    if (keySpec instanceof PKCS8EncodedKeySpec)      {        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;        byte[] encoded = spec.getEncoded();        PrivateKey result;        try          {            return new RSAKeyPairPKCS8Codec().decodePrivateKey(encoded);          }        catch (RuntimeException x)          {            InvalidKeySpecException y = new InvalidKeySpecException();            y.initCause(x);            throw y;          }      }    throw new InvalidKeySpecException("Unsupported (private) key specification");  }