Code example for Random

Methods: nextBytes

0
    //Static IV ? potential reuse over time ? 
    static byte[] iv = new byte[16];
 
    public static void init() { 
        Security.addProvider(new BouncyCastleProvider());
        r.nextBytes(iv);
    } 
 
 
    public static void encrypt(String message) throws Exception {
        //IV 
        IvParameterSpec ivSpec = new IvParameterSpec(iv);
 
        //Key 
        KeyGenerator generator = KeyGenerator.getInstance("AES");
        generator.init(128);
        SecretKey secretKey = generator.generateKey();
 
        //Encrypt 
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");