generate Block Cipher Key - Android java.security

Android examples for java.security:Key

Description

generate Block Cipher Key

Demo Code


//package com.java2s;

import java.security.NoSuchAlgorithmException;

import javax.crypto.KeyGenerator;

import javax.crypto.SecretKey;

public class Main {
    private static final String SYMMETRIC_ALGORITHM = "AES";

    public static SecretKey generateBlockCipherKey(int keySize) {
        KeyGenerator kgen;//from  w ww.ja  v a  2 s  .  c  om
        try {
            kgen = KeyGenerator.getInstance(SYMMETRIC_ALGORITHM);
            kgen.init(keySize);
            return kgen.generateKey();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials