encrypt with AES key - Android java.security

Android examples for java.security:AES

Description

encrypt 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_encrypt(String text, SecretKeySpec sks) {
        byte[] encodedBytes = null;
        try {/* www  .j av  a  2s.  com*/
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.ENCRYPT_MODE, sks);
            encodedBytes = c.doFinal(text.getBytes());
        } catch (Exception e) {
            Log.e("", "AES encryption error");
            e.printStackTrace();
        }
        return Base64.encodeToString(encodedBytes, Base64.DEFAULT);
    }
}

Related Tutorials