@Test
public void canEncrypt_complexCsvFile() throws Exception {
URL srcCsv = JuUrl.resource("ch/inftec/ju/util/security/JuSecurityUtilsTest_toBeEncrypted_complex.csv");
JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor().password("secret").createTextEncryptor();
String res = JuSecurityUtils.performEncryption()
.csvFile(srcCsv)
.encryptor(encryptor)
.encryptToString();
List<String> lines = NewLineReader.createByString(res).getLines();
Assert.assertEquals(3, lines.size());
Assert.assertEquals("NormalValue;", lines.get(0));
// Check first encrypted value
Assert.assertTrue(lines.get(1).startsWith("\"ENC("));
Assert.assertTrue(lines.get(1).endsWith(")\";another value"));
String encryptedVal1 = new RegexUtil("\"ENC\\((.*)\\)").getMatches(lines.get(1))[0].getGroups()[0];
Assert.assertEquals("secret(;)", encryptor.decrypt(encryptedVal1));
// Check second encrypted value
Assert.assertTrue(lines.get(2).startsWith("\"ENC("));
Assert.assertTrue(lines.get(2).endsWith(")\";"));
String encryptedVal2 = new RegexUtil("\"ENC\\((.*)\\)").getMatches(lines.get(2))[0].getGroups()[0];
Assert.assertEquals("\"secret;\"", encryptor.decrypt(encryptedVal2));
}