Quantcast
Channel: The Things Network - Latest posts
Viewing all articles
Browse latest Browse all 116640

Message Decryption for Java

$
0
0

Hi Arjan, thanks for your suggestion!

Well in the decrypt() method you can actually see that the input actually is being decoded, so you need to supply an encoded byte array. When you supply it with an array that is not Base64 encoded you will receive an illegal Base64 character exception from the decoder.

I have edited the test method a bit, because I found out I actually commented out some stuff in the decrypt method(). Now my test looks like this:

public static void testDecoder() throws Exception {
    byte [] key = new byte [] {0x2B, 0x7E, 0x15, 0x16, 0x28, (byte) 0xAE, (byte) 0xD2, (byte) 0xA6, (byte) 0xAB, (byte) 0xF7, 0x15, (byte) 0x88, 0x09, (byte) 0xCF, 0x4F, 0x3C};
    byte [] iv = new byte [] {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};

    String message = "thisisverysecret";

    byte[] encrypted = encryptAES(message.getBytes(), key, iv);
    byte[] encoded = Base64.getEncoder().encode(encrypted);
    String decrypted = decrypt(encoded, key, iv);

    System.out.println(decrypted);
}

Any suggestions are very welcome!


Viewing all articles
Browse latest Browse all 116640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>