@Test public void encrypt() throws Exception { String string0 = EncryptUtil.encrypt(KEY, SAMPLE1); Assert.assertEquals(SAMPLE1_ENC, string0); string0 = EncryptUtil.encrypt(KEY, SAMPLE2); Assert.assertEquals(SAMPLE2_ENC, string0); string0 = EncryptUtil.encrypt(KEY, SAMPLE3); Assert.assertEquals(SAMPLE3_ENC, string0); }
public static String encrypt(String key, String source) { try { Key key0 = getKey(key); Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, key0); byte[] cleartext = source.getBytes(); byte[] ciphertext = desCipher.doFinal(cleartext); return Base64Codec.encode(ciphertext); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }
EncryptUtil { public static String encrypt(String key, String source) { try { Key key0 = getKey(key); Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, key0); byte[] cleartext = source.getBytes(); byte[] ciphertext = desCipher.doFinal(cleartext); return Base64Codec.encode(ciphertext); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } }
EncryptUtil { public static String encrypt(String key, String source) { try { Key key0 = getKey(key); Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, key0); byte[] cleartext = source.getBytes(); byte[] ciphertext = desCipher.doFinal(cleartext); return Base64Codec.encode(ciphertext); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }  }
EncryptUtil { public static String encrypt(String key, String source) { try { Key key0 = getKey(key); Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, key0); byte[] cleartext = source.getBytes(); byte[] ciphertext = desCipher.doFinal(cleartext); return Base64Codec.encode(ciphertext); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }  static String generateKey(); static String encrypt(String key, String source); static String decrypt(String key, String source); }
EncryptUtil { public static String encrypt(String key, String source) { try { Key key0 = getKey(key); Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, key0); byte[] cleartext = source.getBytes(); byte[] ciphertext = desCipher.doFinal(cleartext); return Base64Codec.encode(ciphertext); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }  static String generateKey(); static String encrypt(String key, String source); static String decrypt(String key, String source);  }