// From http://code.calum.org/ public static byte[] decrypt(byte[] cipherBytes, PrivateKey privKey) { Logger log = Logger.getLogger("foo"); // log.info("PrivateKey passed to us as " + privKey.toString()); try { Cipher cipher = Cipher.getInstance(Main.ASYMMETRIC); cipher.init(Cipher.DECRYPT_MODE, privKey); byte[] returnBytes = cipher.doFinal(cipherBytes); //log.info("Successfully decrypted data"); return returnBytes; } catch (InvalidKeyException ex) { ex.printStackTrace(); } catch (BadPaddingException ex) { // No need to show this. } catch (NoSuchPaddingException ex) { ex.printStackTrace(); } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } catch (IllegalBlockSizeException ex) { //Too big? Max 245 bytes. log.info(ex.toString()); } return null; }