Hello everybody,

I'm developing my program and I need to send over network encrypted data. I can do this but when I call method responsible for decrypting I receive null. It seems that there's something missing in my code and I don't know what.Let me show you my code:

public String decrypt(String text) {
        try {
            encrypted = new sun.misc.BASE64Decoder().decodeBuffer(text);
            this.text = decrypter.doFinal(encrypted);
            return new String(this.text, "UTF8");
        } catch (javax.crypto.BadPaddingException e) {
        } catch (IllegalBlockSizeException e) {
        } catch (UnsupportedEncodingException e) {
        } catch (java.io.IOException e) {
        }
        return null;
    }

What's missing in your code is all the e.printStackTrace(); statements in your catch blocks. Right now you could be getting any of those exceptions and you won't know.
As a general rule you should NEVER have an empty catch in a new program unless you are very sure why you want to ignore that exception.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.