title: Blowfish encryption Android
body: <p>I want to encrypt a String with Blowfish in my Android App. The result should be a string because I will send it to my server.
  I have following code:</p>
  
  <pre><code>KeyGenerator keygenerator;
  try {
      keygenerator = KeyGenerator.getInstance("Blowfish");
      SecretKey secretkey = keygenerator.generateKey();
  
      String Key = settings.getString("key", "");
      byte[] KeyData = Key.getBytes();
      SecretKeySpec KS = new SecretKeySpec(KeyData, "Blowfish");
      Cipher cipher = Cipher.getInstance("Blowfish");
      cipher.init(Cipher.ENCRYPT_MODE, KS);
  
      byte[] encrypted = cipher.doFinal(message.getBytes());
      message = new String(encrypted, "UTF-8");
  
      System.out.println("encrypt ok");
  } catch (Exception e){
      System.out.println("encrypt error");
  }
  </code></pre>
  
  <p>The Problem is, that the variable message contains something like</p>
  
  <blockquote>
    <p>R??C?    j</p>
  </blockquote>
  
  <p>But when I decrypt this with Javascript (the JS works fine...) there is returned an empty string... (I couldn't see anything on my website)</p>
  
  <p>I think that the problem is near</p>
  
  <pre><code>message = new String(encrypted, "UTF-8");
  </code></pre>
  
  <p>But how can I resolve the problem?</p>