Android AES Decrypt decrypt(byte[] content, String password)

Here you can find the source of decrypt(byte[] content, String password)

Description

decrypt

Declaration

public static byte[] decrypt(byte[] content, String password) 

Method Source Code

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

public class Main {

    public static byte[] decrypt(byte[] content, String password) {
        byte[] result = null;
        try {/*from w ww .j ava  2  s . c  o  m*/
            SecretKeySpec key = new SecretKeySpec(
                    getRawKey(password.getBytes()), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, key);
            result = cipher.doFinal(content);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    private static byte[] getRawKey(byte[] seed) throws Exception {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
        sr.setSeed(seed);
        kgen.init(128, sr);
        SecretKey skey = kgen.generateKey();
        byte[] raw = skey.getEncoded();
        return raw;
    }
}

Related

  1. decrypt(String src)
  2. decrypt(byte[] content, String key)
  3. decrypt(byte[] content, String password)
  4. decrypt(byte[] content, String password)
  5. decrypt(byte[] content, String password)
  6. decrypt(byte[] content, String password)
  7. decrypt(byte[] data, Key key)
  8. decrypt(byte[] data, Key key, String cipherAlgorithm)
  9. decrypt(byte[] data, byte[] key)