title: AES with Base64 key encryption in android
body: <p>I am making an android application in which I am supposed to encrypt the passwords I take from the user and send it to my app engine. I want to the use the AES technique with a Base64 key. I am new to encryption/decryption so i used the code asked in this <a href="https://stackoverflow.com/questions/4816771/android-encryption">question</a>. I changed the key and replaced it with mine. This is my code:</p>
  <pre><code>public String encrypt(String dataToEncrypt)
              throws NoSuchAlgorithmException, NoSuchPaddingException,
              InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
          // I'm using AES encription
  
          if (!dataToEncrypt.equals(&quot;&quot;)) {
              String key = &quot;rEqrHrhdd9I1sg==&quot;;
  
              Cipher c = Cipher.getInstance(&quot;AES&quot;);
              SecretKeySpec k;
              try {
                  k = new SecretKeySpec(key.getBytes(), &quot;AES&quot;);
                  c.init(Cipher.ENCRYPT_MODE, k);
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              return new String(c.doFinal(Base64.decode(dataToEncrypt, 0)));
          }
          return &quot;&quot;;
      }
  </code></pre>
  <p>But sometimes I get an error &quot;java.lang.IllegalArgumentException: bad base-64&quot; when i try to encrypt certain strings, say &quot;asdasdasd&quot; gives this error when i am encrypting it. Can anyone please tell me what the problem is??<br />
  -Thanks in advance</p>