From ce45844b7fbc9e49548545eac7a36aa8c6b5cd57 Mon Sep 17 00:00:00 2001 From: microwin7 Date: Sat, 24 Feb 2024 05:10:57 +0300 Subject: [PATCH] [FIX] Encrypted ClientParams test for java 8 --- .../gravit/launcher/SecurityHelperTests.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java b/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java index 4a78442d..ec63ee84 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; import javax.crypto.CipherInputStream; @@ -28,20 +29,18 @@ public void aesStreamTest() throws Exception { byte[] seed = SecurityHelper.randomAESKey(); byte[] encrypted; ByteArrayOutputStream s = new ByteArrayOutputStream(); - try(OutputStream o = new CipherOutputStream(s, SecurityHelper.newAESEncryptCipher(seed))) { - try(ByteArrayInputStream i = new ByteArrayInputStream(bytes)) { - i.transferTo(o); + try (OutputStream o = new CipherOutputStream(s, SecurityHelper.newAESEncryptCipher(seed))) { + try (ByteArrayInputStream i = new ByteArrayInputStream(bytes)) { + IOHelper.transfer(i, o); } } encrypted = s.toByteArray(); byte[] decrypted; - ; - try(InputStream i = new CipherInputStream(new ByteArrayInputStream(encrypted), SecurityHelper.newAESDecryptCipher(seed))) { - ByteArrayOutputStream s2 = new ByteArrayOutputStream(); - try(s2) { - i.transferTo(s2); + try (InputStream i = new CipherInputStream(new ByteArrayInputStream(encrypted), SecurityHelper.newAESDecryptCipher(seed))) { + try (ByteArrayOutputStream s2 = new ByteArrayOutputStream()) { + IOHelper.transfer(i, s2); + decrypted = s2.toByteArray(); } - decrypted = s2.toByteArray(); } Assertions.assertArrayEquals(bytes, decrypted); }