title: TripleDES algorithm generates different outcome when called from android
body: <p>I have a simple java web application which is built by apache wicket. When I am registering users in the web app, I encrypt the password that they enter using tripledes and save it to the db. In the login page when they enter the same password, I encrypt it and pass the encrypted password to the db, to check if it is correct.</p>
  
  <p>Now I am working on building an android app which will have same login functionality.</p>
  
  <p>In the android app login page I am using same encryption library for encrypting password and I use the same key and initialization vector for both platforms, but if I try to enter for same password string in android, TripleDes algorithm generates completely different encrypted password(much longer). And therefore login fails from android device. What I also noticed is encrypted password that android generates can not be decrypted, it throws an exception.</p>
  
  <p>I am thinking that there might be a string encoding issue difference between two platforms, but can't figure out what causes that and how to fix it.</p>
  
  <p>Here's the algorithm that I use:</p>
  
  <pre><code>public class TripleDES {
  private String key;
  private byte[] initializationVector;
  
  public TripleDES(String key, byte[] initializationVector)
  {
      this.key = key;
      this.initializationVector = initializationVector;
  }
  
  public String encryptText(String plainText) throws Exception{
  //----  Use specified 3DES key and IV from other source -------------------------
    byte[] plaintext = plainText.getBytes();
    byte[] tdesKeyData = key.getBytes();
  
    System.out.println("plain text length: " + plaintext.length);
    System.out.println("key length: " + tdesKeyData.length);
  
  
    Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    SecretKeySpec    myKey = new SecretKeySpec(tdesKeyData, "DESede");
    IvParameterSpec ivspec = new IvParameterSpec(initializationVector);
  
    c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec);
    byte[] cipherText = c3des.doFinal(plaintext);
  
    return Base64Coder.encodeString(new String(cipherText));
  }
  
  public String decryptText(String encryptedText) throws Exception{
      //----  Use specified 3DES key and IV from other source -------------------
        byte[] enctext = Base64Coder.decode(encryptedText);
        byte[] tdesKeyData = key.getBytes();
  
  
        Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding");
        SecretKeySpec    myKey = new SecretKeySpec(tdesKeyData, "DESede");
        IvParameterSpec ivspec = new IvParameterSpec(initializationVector);
  
        c3des.init(Cipher.DECRYPT_MODE, myKey, ivspec);
        byte[] cipherText = c3des.doFinal(enctext);
        return new String(cipherText);
      }
  </code></pre>
  
  <p>}</p>