Bom dia amigos, estou com um problema meu código esta funcionando perfeitamente mais apenas dentro do main não estou sabendo chamar o metodo de um botão, segue o codigo, desde já agradeço a colaboração de todos.
Este é o codigo para criptografar e descriptografar:
public void criptografa(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128); // 192 and 256 bits may not be available
// Generate the secret key specs.
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
// Instantiate the cipher
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
// o nome marcelo é que sera criptografado em 128 bits
byte[] encrypted = cipher.doFinal((args.length == 0 ? "marcelo" : args[0]).getBytes());
System.out.println("encrypted string: " + asHex(encrypted));
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] original = cipher.doFinal(encrypted);
String originalString = new String(original);
System.out.println("Original string: "
+ originalString + " " + asHex(original));
}
E esta é a maneira que estou tentando chamar o metodo:
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
this.criptografa(args);
}