Ejemplo n.º 1
0
 public String encrypt(String str) {
   try {
     SecretKeySpec key = new SecretKeySpec(this.key.getBytes(), "Blowfish");
     Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
     cipher.init(Cipher.ENCRYPT_MODE, key);
     return Base64.encodeBytes(cipher.doFinal(pad(str).getBytes()));
   } catch (Exception e) {
     return null;
   }
 }
Ejemplo n.º 2
0
 public String decrypt(String str) {
   try {
     SecretKeySpec key = new SecretKeySpec(this.key.getBytes(), "Blowfish");
     Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
     cipher.init(Cipher.DECRYPT_MODE, key);
     byte[] decrypted = cipher.doFinal(Base64.decode(str));
     return new String(decrypted).replaceAll("\\x00+$", "");
   } catch (Exception e) {
     return null;
   }
 }