decrypt with AES Key - Android java.security

Android examples for java.security:AES

Description

decrypt with AES Key

Demo Code


//package com.java2s;
import android.util.Base64;
import android.util.Log;

import javax.crypto.Cipher;

import javax.crypto.spec.SecretKeySpec;

public class Main {
    public static String v_decrypt(String text, SecretKeySpec sks) {
        byte[] decodedBytes = null;
        byte[] encodedBytes = null;
        encodedBytes = Base64.decode(text, Base64.DEFAULT);
        try {//from   w w w.  j a va  2s  . c  o  m
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.DECRYPT_MODE, sks);
            decodedBytes = c.doFinal(encodedBytes);
        } catch (Exception e) {
            Log.e("", "AES decryption error");
            e.printStackTrace();
        }
        return new String(decodedBytes);
    }
}

Related Tutorials