private byte[] finishTransformation(Cipher crypter, byte[] bytes) throws CryptException { try { return crypter.doFinal(bytes); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new CryptException(e); } }
private SecretKeyFactory getSecretKeyFactory() throws CryptException { try { return SecretKeyFactory.getInstance(ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new CryptException(e); } }
private Cipher getCipherInstance() throws CryptException { try { return Cipher.getInstance(CIPHER_TYPE); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { throw new CryptException(e); } }
private void initialise(PBEParameterSpec ps, SecretKey k, Cipher crypter, int decryptMode) throws CryptException { try { crypter.init(decryptMode, k, ps); } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { throw new CryptException(e); } }
private SecretKey getSecretKey(SecretKeyFactory kf) throws CryptException { try { return kf.generateSecret(new javax.crypto.spec.PBEKeySpec(SECRET_KEY.toCharArray())); } catch (InvalidKeySpecException e) { throw new CryptException(e); } }
private byte[] getDecode(String encryption_subject) throws CryptException { try { return Base64.decode(encryption_subject); } catch (Base64DecoderException e) { throw new CryptException(e); } } }
private String getString(String encryption_subject, Cipher crypter) throws CryptException { try { return new String(finishTransformation(crypter, getDecode(encryption_subject)), CHARSET); } catch (UnsupportedEncodingException e) { throw new CryptException(e); } }
private String encode(String encryption_subject, Cipher crypter) throws CryptException { try { return Base64.encode(finishTransformation(crypter, encryption_subject.getBytes(CHARSET))); } catch (UnsupportedEncodingException e) { throw new CryptException(e); } }