Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>All your problems derive from this</p> <pre><code>byte[] encrypted = cipher.doFinal(toEncrypt.getBytes()); return encrypted; </code></pre> <p>Which are enclosed in a try, catch block, the problem is that in case the program found an exception you are not returning anything. Put it like this (modify it as your program logic stands):</p> <pre><code>public static byte[] encrypt(String toEncrypt) throws Exception{ try{ String plaintext = toEncrypt; String key = "01234567890abcde"; String iv = "fedcba9876543210"; SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE,keyspec,ivspec); byte[] encrypted = cipher.doFinal(toEncrypt.getBytes()); return encrypted; } catch(Exception e){ return null; // Always must return something } } </code></pre> <p>For the second one you must catch the Exception from the <em>encrypt</em> method call, like this (also modify it as your program logic stands):</p> <pre><code>public void actionPerformed(ActionEvent e) . . . try { byte[] encrypted = encrypt(concatURL); String encryptedString = bytesToHex(encrypted); content.removeAll(); content.add(new JLabel("Concatenated User Input --&gt;" + concatURL)); content.add(encryptedTextField); setContentPane(content); } catch (Exception exc) { // TODO: handle exception } } </code></pre> <p>The lessons you must learn from this:</p> <ul> <li>A method with a return-type must <strong>always</strong> return an object of that type, I mean in all possible scenarios</li> <li>All checked exceptions must <strong>always</strong> be handled</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload