Demo entry 6315342



Submitted by anonymous on Nov 01, 2016 at 16:35
Language: Java. Code size: 529 Bytes.

// generate key
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
SecretKey key = keyGen.generateKey();

// generate initialization vector
SecureRandom random = new SecureRandom();
byte init_vector[16] = new byte[];

// init cipher
IvParameterSpec iv = new IvParameterSpec(init_vector);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, key, iv);

// encrypt text
byte[] encrypted = cipher.doFinal(msg.getBytes());

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).