@Test public void testEncrypt() { String testToEncrypt = "Ey hello!"; String textEncrypted = CipherHelper.encrypt(testToEncrypt); assertNotEquals(testToEncrypt, textEncrypted); }
public static String encrypt(String text) { String base64EncryptedString = ""; if (!StringUtils.isBlank(text)) { try { String secretKey = getSecretKey(); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = text.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encode(buf, Base64.DEFAULT); base64EncryptedString = new String(base64Bytes); } catch (Exception e) { Timber.e("encrypt: %s", e); } } return base64EncryptedString; }
CipherHelper { public static String encrypt(String text) { String base64EncryptedString = ""; if (!StringUtils.isBlank(text)) { try { String secretKey = getSecretKey(); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = text.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encode(buf, Base64.DEFAULT); base64EncryptedString = new String(base64Bytes); } catch (Exception e) { Timber.e("encrypt: %s", e); } } return base64EncryptedString; } }
CipherHelper { public static String encrypt(String text) { String base64EncryptedString = ""; if (!StringUtils.isBlank(text)) { try { String secretKey = getSecretKey(); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = text.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encode(buf, Base64.DEFAULT); base64EncryptedString = new String(base64Bytes); } catch (Exception e) { Timber.e("encrypt: %s", e); } } return base64EncryptedString; }  }
CipherHelper { public static String encrypt(String text) { String base64EncryptedString = ""; if (!StringUtils.isBlank(text)) { try { String secretKey = getSecretKey(); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = text.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encode(buf, Base64.DEFAULT); base64EncryptedString = new String(base64Bytes); } catch (Exception e) { Timber.e("encrypt: %s", e); } } return base64EncryptedString; }  static String getMd5Hash(String key); static String encrypt(String text); static String decrypt(String text); }
CipherHelper { public static String encrypt(String text) { String base64EncryptedString = ""; if (!StringUtils.isBlank(text)) { try { String secretKey = getSecretKey(); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = text.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encode(buf, Base64.DEFAULT); base64EncryptedString = new String(base64Bytes); } catch (Exception e) { Timber.e("encrypt: %s", e); } } return base64EncryptedString; }  static String getMd5Hash(String key); static String encrypt(String text); static String decrypt(String text);  }