get AES Standard Secret Key - Android java.security

Android examples for java.security:AES

Description

get AES Standard Secret Key

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class Main {
    @SuppressLint("TrulyRandom")
    public static SecretKey getStandardSecretKey()
            throws NoSuchAlgorithmException {
        final int outputKeyLength = 256;
        SecureRandom secureRandom = new SecureRandom();
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(outputKeyLength, secureRandom);
        SecretKey secretkey = keyGenerator.generateKey();
        return secretkey;
    }/* w  w w .j a v a 2s . c  om*/
}

Related Tutorials