[FIX] XOR изменяющий оригинальный массив.

This commit is contained in:
zaxar163 2019-10-26 20:00:08 +03:00
parent 4ccf11f461
commit 585fb06151

View file

@ -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;
}
}
}