@Test public void decryptReturnsOriginalString() throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, InvalidKeySpecException { String stringToEncrypt = "My super secret 1337 P@SSW0rDz"; byte[] encryptedString = encryptor.encrypt(stringToEncrypt.getBytes()); byte[] result = encryptor.decrypt(encryptedString); // System.out.println("before: " + stringToEncrypt); // System.out.println("after : " + new String(encryptedString)); String resultString = new String(result); // System.out.println("unencrypted: " + resultString); assertEquals(stringToEncrypt, resultString); }
@Test public void encryptedDataHasLengthOf48Bytes() throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, InvalidKeySpecException { String stringToEncrypt = "My super secret 1337 P@SSW0rDz"; byte[] result = encryptor.encrypt(stringToEncrypt.getBytes()); // System.out.println("before: " + stringToEncrypt); // System.out.println("after : " + new String(result)); assertEquals(48, result.length); // 32 (data) + 16 (iv) }