Q:

Android Sdk: BASE64 Encoder/Decoder not importing

So I am trying to implement a string encryption class that I got from link to code
and when I try to put it into my android project, I receive the following errors:

Description   Resource    Path    Location    Type The import sun cannot be
  resolved  SimpleProtector.java    /EncryptedSMS/src/com/nsaers/encryptedsms   line
  7 Java Problem BASE64Decoder cannot be resolved to a
  type  SimpleProtector.java    /EncryptedSMS/src/com/nsaers/encryptedsms   line
  29    Java Problem BASE64Encoder cannot be resolved to a
  type  SimpleProtector.java    /EncryptedSMS/src/com/nsaers/encryptedsms   line
  21    Java Problem

Any ideas?
Here is my code of the class:
package com.nsaers.encryptedsms;

import java.security.Key;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class SimpleProtector {
    private static final String ALGORITHM = "AES";
    private static final byte[] keyValue = new byte[] { 'T', 'h', 'i', 's',
            'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' };

    public static String encrypt(String valueToEnc) throws Exception {
        Key key = generateKey();
        Cipher c = Cipher.getInstance(ALGORITHM);
        c.init(Cipher.ENCRYPT_MODE, key);
        byte[] encValue = c.doFinal(valueToEnc.getBytes());
        String encryptedValue = new BASE64Encoder().encode(encValue);
        return encryptedValue;
    }

    public static String decrypt(String encryptedValue) throws Exception {
        Key key = generateKey();
        Cipher c = Cipher.getInstance(ALGORITHM);
        c.init(Cipher.DECRYPT_MODE, key);
        byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedValue);
        byte[] decValue = c.doFinal(decordedValue);
        String decryptedValue = new String(decValue);
        return decryptedValue;
    }

    private static Key generateKey() throws Exception {
        Key key = new SecretKeySpec(keyValue, ALGORITHM);
        // SecretKeyFactory keyFactory =
        // SecretKeyFactory.getInstance(ALGORITHM);
        // key = keyFactory.generateSecret(new DESKeySpec(keyValue));
        return key;
    }
}

A:

Use the Base64 class in the Android SDK instead of BASE64Encoder / BASE64Decoder. The API may be slightly different, but it'll do what you need.
However, your code will still not be ideal: any time you use String.getBytes or a String constructor which takes a byte array, you should specify the encoding to use - UTF-8 is probably the most appropriate. Currently you'll use the system default encoding, which may be UTF-8 (I've a feeling it always is in Android) but leaves your code pretty brittle.

