generate AES Key - Android java.security

Android examples for java.security:AES

Description

generate AES Key

Demo Code


//package com.java2s;

import java.security.Key;
import java.security.SecureRandom;

import javax.crypto.KeyGenerator;

public class Main {

    private static final int ENCRYPT_KEY_LENGTH = 128;

    private static Key generateKey() {
        try {// www .  j  a v a2 s  .co m
            KeyGenerator generator = KeyGenerator.getInstance("AES");
            SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
            generator.init(ENCRYPT_KEY_LENGTH, random);
            return generator.generateKey();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related Tutorials