mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Encrypted ClientParams test for java 8
This commit is contained in:
parent
b15500f6fa
commit
ce45844b7f
1 changed files with 8 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
import javax.crypto.CipherInputStream;
|
import javax.crypto.CipherInputStream;
|
||||||
|
@ -28,21 +29,19 @@ public void aesStreamTest() throws Exception {
|
||||||
byte[] seed = SecurityHelper.randomAESKey();
|
byte[] seed = SecurityHelper.randomAESKey();
|
||||||
byte[] encrypted;
|
byte[] encrypted;
|
||||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||||
try(OutputStream o = new CipherOutputStream(s, SecurityHelper.newAESEncryptCipher(seed))) {
|
try (OutputStream o = new CipherOutputStream(s, SecurityHelper.newAESEncryptCipher(seed))) {
|
||||||
try(ByteArrayInputStream i = new ByteArrayInputStream(bytes)) {
|
try (ByteArrayInputStream i = new ByteArrayInputStream(bytes)) {
|
||||||
i.transferTo(o);
|
IOHelper.transfer(i, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
encrypted = s.toByteArray();
|
encrypted = s.toByteArray();
|
||||||
byte[] decrypted;
|
byte[] decrypted;
|
||||||
;
|
try (InputStream i = new CipherInputStream(new ByteArrayInputStream(encrypted), SecurityHelper.newAESDecryptCipher(seed))) {
|
||||||
try(InputStream i = new CipherInputStream(new ByteArrayInputStream(encrypted), SecurityHelper.newAESDecryptCipher(seed))) {
|
try (ByteArrayOutputStream s2 = new ByteArrayOutputStream()) {
|
||||||
ByteArrayOutputStream s2 = new ByteArrayOutputStream();
|
IOHelper.transfer(i, s2);
|
||||||
try(s2) {
|
|
||||||
i.transferTo(s2);
|
|
||||||
}
|
|
||||||
decrypted = s2.toByteArray();
|
decrypted = s2.toByteArray();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Assertions.assertArrayEquals(bytes, decrypted);
|
Assertions.assertArrayEquals(bytes, decrypted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue