i have this code .. but i want to build a java swing gui .. whichwill have a tex
ID: 3615182 • Letter: I
Question
i have this code .. but i want to build a java swing gui .. whichwill have a text box to input the password string and a gui spaceto display the output informationi am new to java gui.. can you create this sample gui for me ..when i understand this basic gui further changes to the gui as perrequirement i will do on my own. thanks
package org.temp2.cod1;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;
/**
* This program generates a AES key, retrieves its rawbytes, and
* then reinstantiates a AES key from the keybytes.
* The reinstantiated key is used to initialize a AEScipher for
* encryption and decryption.
*/
public class AES1 {
/**
* Turns array of bytes into string
*
* @param buf Array ofbytes to convert to hex string
* @return Generated hexstring
*/
public static String asHex (byte buf[]){
StringBuffer strbuf = newStringBuffer(buf.length * 2);
int i;
for (i = 0; i < buf.length; i++){
if (((int) buf[i] & 0xff)< 0x10)
strbuf.append("0");
strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
}
return strbuf.toString();
}
public static void main(String[] args)throws Exception {
String message="This is justan example";
// Get the KeyGenerator
KeyGenerator kgen =KeyGenerator.getInstance("AES");
kgen.init(128); // 192 and 256bits may not be available
// Generate the secret keyspecs.
SecretKey skey =kgen.generateKey();
byte[] raw =skey.getEncoded();
SecretKeySpec skeySpec = newSecretKeySpec(raw, "AES");
// Instantiate the cipher
Cipher cipher =Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted =
cipher.doFinal((args.length == 0 ?
"This isjust an example" : args[0]).getBytes());
System.out.println("encryptedstring: " + asHex(encrypted));
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] original =
cipher.doFinal(encrypted);
String originalString = newString(original);
System.out.println("Originalstring: " +
originalString + "" + asHex(original));
}
}