Example #1
0
 void initCipher() {
   try {
     b64Decoder = new BASE64Decoder();
     b64Encoder = new BASE64Encoder();
     Provider sunJce = new com.sun.crypto.provider.SunJCE();
     Security.addProvider(sunJce);
     byte[] raw = b64Decoder.decodeBuffer(key);
     SecretKeySpec skeySpec = new SecretKeySpec(raw, "Blowfish");
     deCipher = Cipher.getInstance("Blowfish");
     deCipher.init(Cipher.DECRYPT_MODE, skeySpec);
     enCipher = Cipher.getInstance("Blowfish");
     enCipher.init(Cipher.ENCRYPT_MODE, skeySpec);
   } catch (Exception ex) {
     textPane.setText("Unable to create the cipher");
   }
 }
Example #2
0
 private String decrypt(String s) {
   try {
     byte[] encrypted = b64Decoder.decodeBuffer(s);
     byte[] decrypted = deCipher.doFinal(encrypted);
     return new String(decrypted);
   } catch (Exception ex) {
     return "error";
   }
 }