Android AES Encrypt encrypt(String dataPassword, String cleartext)

Here you can find the source of encrypt(String dataPassword, String cleartext)

Description

encrypt

License

Apache License

Declaration

public static String encrypt(String dataPassword, String cleartext)
        throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;

public class Main {
    private static final byte[] ENCRYPT_IV = { 0x0, 0x0, 0x0, 0x0, 0x0,
            0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
    private static final String CHARSET = "UTF-8";

    public static String encrypt(String dataPassword, String cleartext)
            throws Exception {
        IvParameterSpec zeroIv = new IvParameterSpec(ENCRYPT_IV);
        SecretKeySpec key = new SecretKeySpec(dataPassword.getBytes(),
                "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
        byte[] encryptedData = cipher.doFinal(cleartext.getBytes(CHARSET));

        return new String(Base64.encodeBase64(encryptedData));
    }/*from w w  w.j  a v  a2 s.com*/
}

Related

  1. encrypt(String content, String password)
  2. encrypt(String content, String password)
  3. encrypt(String content, String password)
  4. encrypt(String content, String password)
  5. encrypt(String data)
  6. encrypt(String key, String src)
  7. encrypt(String key, String src)
  8. encrypt(String seed, String clearText)
  9. encrypt(String seed, String clearText)