AES decrypt String - Android java.security

Android examples for java.security:AES

Description

AES decrypt String

Demo Code

import android.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class Main{

    public static String decrypt(String code) throws Exception {
        return new String(getCipher(Cipher.DECRYPT_MODE).doFinal(
                Base64.decode(code, Base64.NO_PADDING)));
    }/*from w ww  .j a v  a2s .  co  m*/
    private static Cipher getCipher(int ENCRYPT_MODE) throws Exception {

        Cipher cipher = Cipher.getInstance(TRANSFORMATION);
        cipher.init(ENCRYPT_MODE, new SecretKeySpec(SECRET_KEY.getBytes(),
                ALGORITHM), new IvParameterSpec(SECRET_IV.getBytes()));

        return cipher;
    }

}

Related Tutorials