Android AES Decrypt decrypt(String data)

Here you can find the source of decrypt(String data)

Description

decrypt

Declaration

public static String decrypt(String data) 

Method Source Code

//package com.java2s;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import android.util.Base64;

public class Main {
    private static final String seed = "This is a secret";

    public static String decrypt(String data) {
        try {//from  w  w w.  ja va2s  . c  o  m
            SecretKeySpec sks = null;
            byte[] decodedBytes = null;
            byte[] encodedBytes = Base64.decode(data, Base64.DEFAULT);

            SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
            sr.setSeed(seed.getBytes());
            KeyGenerator kg = KeyGenerator.getInstance("AES");
            kg.init(128, sr);
            sks = new SecretKeySpec((kg.generateKey()).getEncoded(), "AES");

            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.DECRYPT_MODE, sks);
            decodedBytes = c.doFinal(encodedBytes);

            return new String(decodedBytes);
        } catch (Exception e) {

        }

        return null;
    }
}

Related

  1. decrypt(String content, String password)
  2. decrypt(String dataPassword, String encrypted)
  3. decrypt(String encrypted)
  4. decrypt(String key, String encrypted)
  5. decrypt(String key, String src)