From 585fb0615129cc269484662b9481068478b92b77 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 26 Oct 2019 20:00:08 +0300 Subject: [PATCH] =?UTF-8?q?[FIX]=20XOR=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=8F=D1=8E=D1=89=D0=B8=D0=B9=20=D0=BE=D1=80=D0=B8=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B8=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/utils/helper/CryptoHelper.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java index 727243a5..7106fca5 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java @@ -1,5 +1,6 @@ package pro.gravit.utils.helper; +import java.io.OutputStream; import java.util.Objects; import java.util.function.LongSupplier; @@ -24,12 +25,26 @@ public static byte[] decode(byte[] pText, String pKey) { return res; } + public static void encodeOrig(byte[] txt, String pKey) { + Objects.requireNonNull(txt); + Objects.requireNonNull(pKey); + byte[] key = SecurityHelper.fromHex(pKey); + for (int i = 0; i < txt.length; i++) + txt[i] = (byte) (txt[i] ^ key[i % key.length]); + } + + public static void decodeOrig(byte[] pText, String pKey) { + Objects.requireNonNull(pText); + Objects.requireNonNull(pKey); + byte[] key = SecurityHelper.fromHex(pKey); + for (int i = 0; i < pText.length; i++) + pText[i] = (byte) (pText[i] ^ key[i % key.length]); + } + + public static String randomToken(int depth) { VerifyHelper.verifyInt(depth, VerifyHelper.POSITIVE, "Depth must be positive"); - StringBuilder sb = new StringBuilder(SecurityHelper.TOKEN_STRING_LENGTH*depth); - for (int i = 0; i < depth; i++) - sb.append(SecurityHelper.randomStringToken()); - return sb.toString(); + return SecurityHelper.toHex(SecurityHelper.randomBytes(SecurityHelper.TOKEN_LENGTH*depth)); } private CryptoHelper() { @@ -50,5 +65,4 @@ public long getAsLong() { return this.rnd; } } - }