Q:

Android AES issue

I need to implement AES algorithm with my Android application, and I created this code below and it works prefectly as Java application, but it seems that Android doesnt recognize JAXB. Because as you can see i use import javax.xml.bind.DatatypeConverter, because I use Datatype converter to convert from byte[] to string...
I tried to import jaxb jar, but it fails again with this error: Conversion to Dalvik format failed with error 1.
How I can fix this?
Here is the code:
public class AESCrypt {

private final Cipher cipher;
private final SecretKeySpec key;
private AlgorithmParameterSpec spec;
private String encryptedText, decryptedText;
ByteArrayOutputStream baos;

public AESCrypt(String password) throws Exception {
    // hash password with SHA-256 and crop the output to 128-bit for key
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.update(password.getBytes("UTF-8"));
    byte[] keyBytes = new byte[16];
    System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length);

    cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    key = new SecretKeySpec(keyBytes, "AES");
    spec = getIV();
    }

public AlgorithmParameterSpec getIV() {
    AlgorithmParameterSpec ivspec;
    byte[] iv = new byte[cipher.getBlockSize()];
    new SecureRandom().nextBytes(iv);
    ivspec = new IvParameterSpec(iv);
    return ivspec;
    }

public String encrypt(String plainText) throws Exception {      
    cipher.init(Cipher.ENCRYPT_MODE, key, spec);
    byte[] encrypted = cipher.doFinal(plainText.getBytes());
    encryptedText = DatatypeConverter.printBase64Binary(encrypted);
    return encryptedText;
}

public String decrypt(String cryptedText) throws Exception {
    cipher.init(Cipher.DECRYPT_MODE, key, spec);
    byte[] bytes = DatatypeConverter.parseBase64Binary(cryptedText);
    byte[] decrypted = cipher.doFinal(bytes);
    decryptedText = new String(decrypted, "UTF-8");
    return decryptedText;
}   

}

A:

The Android library has the class Base64 (android.util.Base64) that is very convenient to convert base64 string to data.

