package assignment2;import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import javax.crypto.spec.SecretKeySpec;public class grp10 {    static String Key = null;    public static byte encrypt(byte key, byte initVector, String value) {        try {            IvParameterSpec iv = new IvParameterSpec(initVector);            SecretKeySpec skeySpec = new SecretKeySpec(key, “AES”);            Cipher cipher = Cipher.getInstance(“AES/CBC/PKCS5PADDING”);            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);            byte encrypted = cipher.doFinal(value.getBytes());            return encrypted;        } catch (Exception ex) {            ex.printStackTrace();        }        return null;    }    public static String decrypt(byte key, byte initVector, byte ciphertext) {        try {            IvParameterSpec iv = new IvParameterSpec(initVector);            SecretKeySpec skeySpec = new SecretKeySpec(key, “AES”);            Cipher cipher = Cipher.getInstance(“AES/CBC/PKCS5PADDING”);            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);            byte original = cipher.doFinal(ciphertext);            return new String(original);        } catch (Exception ex) {            ex.printStackTrace();        }        return null;    }    public static void main(String args) throws Exception{           long startTime1 = System.currentTimeMillis();    byte IV = {‘o’,(byte) ‘½’,’!’,(byte) ‘?’,(byte) ‘ú’,(byte) ‘’,(byte) ‘µ’,(byte) ‘í’,’X’,’f’,’.’,(byte) ‘?’,(byte) ‘¥’,(byte) ‘?’,(byte) ‘à’,’’};            byte key1 ={(byte) ‘ÿ’,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};          java.security.SecureRandom.getInstanceStrong().nextBytes(IV);                byte b= encrypt(key1, IV, “Hello World”);                String r = new String(b);                String res = decrypt(key1,IV,b);                System.out.println(r);                System.out.println(res);                                String rs = new String(key1);                System.out.println(rs);                                long endTime1 = System.currentTimeMillis();                long totalTime = endTime1 – startTime1;                System.out.println(“Time Taken: “+totalTime+  ” ms”);                //—————————————————————-            }}

x

Hi!
I'm Harold!

Would you like to get a custom essay? How about receiving a customized one?

Check it out