private static PrivateKey convertToSunImpl(PrivateKey key){
  PKCS8EncodedKeySpec spec=new PKCS8EncodedKeySpec(key.getEncoded());
  KeyFactory kf;
  try {
    kf=KeyFactory.getInstance(KeyUtil.RSA_ALGORITHM);
    return kf.generatePrivate(spec);
  }
 catch (  NoSuchAlgorithmException|InvalidKeySpecException e) {
    e.printStackTrace();
  }
  return null;
}

private static PrivateKey convertToSunImpl ( PrivateKey key ) { PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec ( key . getEncoded ( ) ) ; KeyFactory kf ; try { kf = KeyFactory . getInstance ( KeyUtil . RSA_ALGORITHM ) ; return kf . generatePrivate ( spec ) ; } catch ( NoSuchAlgorithmException | InvalidKeySpecException e ) { e . printStackTrace ( ) ; } return null ; }
helper method for converting the bouncycastle implementation of a private key to a sun implementation .
