TripleDESCrytor implements Cryptor { @Override public String encrypt(String clear) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String encryptedString = null; try { cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainText = clear.getBytes(UNICODE_FORMAT); byte[] encryptedText = cipher.doFinal(plainText); encryptedString = new String(Base64.encodeBase64(encryptedText), UNICODE_FORMAT); } catch (Exception e) { e.printStackTrace(); } return encryptedString; } TripleDESCrytor(); @Override String encrypt(String clear); static String GEN(); @Override String decrypt(String str); @Override String newKey();  }
@Test public void testEncrypt() throws Exception { System.out.println("encrypt"); String clear = "test"; TripleDESCrytor instance = new TripleDESCrytor(); String expResult = "test"; String result =instance.decrypt(instance.encrypt(clear)); assertEquals(expResult, result); }