@Test public void runTest() { assertEquals("Dl+Cr1z8wRY=", Blowfish.blowfish("TESTING", Mode.ENCRYPT, "EXAMPLEKEY")); assertEquals("TESTING", Blowfish.blowfish("Dl+Cr1z8wRY=", Mode.DECRYPT, "EXAMPLEKEY")); }
public static String blowfish(String input, Mode mode, String key) { String output = ""; org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64(); byte[] keyBytes = key.getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "Blowfish"); if (mode == Mode.ENCRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); output = base64.encodeToString(cipher.doFinal(input.getBytes())); } catch (GeneralSecurityException e) { e.printStackTrace(); } } if (mode == Mode.DECRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); output = new String(cipher.doFinal(base64.decode(input.getBytes()))); } catch (GeneralSecurityException e) { e.printStackTrace(); } } return output; }
Blowfish { public static String blowfish(String input, Mode mode, String key) { String output = ""; org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64(); byte[] keyBytes = key.getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "Blowfish"); if (mode == Mode.ENCRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); output = base64.encodeToString(cipher.doFinal(input.getBytes())); } catch (GeneralSecurityException e) { e.printStackTrace(); } } if (mode == Mode.DECRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); output = new String(cipher.doFinal(base64.decode(input.getBytes()))); } catch (GeneralSecurityException e) { e.printStackTrace(); } } return output; } }
Blowfish { public static String blowfish(String input, Mode mode, String key) { String output = ""; org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64(); byte[] keyBytes = key.getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "Blowfish"); if (mode == Mode.ENCRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); output = base64.encodeToString(cipher.doFinal(input.getBytes())); } catch (GeneralSecurityException e) { e.printStackTrace(); } } if (mode == Mode.DECRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); output = new String(cipher.doFinal(base64.decode(input.getBytes()))); } catch (GeneralSecurityException e) { e.printStackTrace(); } } return output; }  }
Blowfish { public static String blowfish(String input, Mode mode, String key) { String output = ""; org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64(); byte[] keyBytes = key.getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "Blowfish"); if (mode == Mode.ENCRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); output = base64.encodeToString(cipher.doFinal(input.getBytes())); } catch (GeneralSecurityException e) { e.printStackTrace(); } } if (mode == Mode.DECRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); output = new String(cipher.doFinal(base64.decode(input.getBytes()))); } catch (GeneralSecurityException e) { e.printStackTrace(); } } return output; }  static void main(String[] args); static String blowfish(String input, Mode mode, String key); }
Blowfish { public static String blowfish(String input, Mode mode, String key) { String output = ""; org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64(); byte[] keyBytes = key.getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "Blowfish"); if (mode == Mode.ENCRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); output = base64.encodeToString(cipher.doFinal(input.getBytes())); } catch (GeneralSecurityException e) { e.printStackTrace(); } } if (mode == Mode.DECRYPT) { try { Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); output = new String(cipher.doFinal(base64.decode(input.getBytes()))); } catch (GeneralSecurityException e) { e.printStackTrace(); } } return output; }  static void main(String[] args); static String blowfish(String input, Mode mode, String key);  }