Update libac version

Update libz version
This commit is contained in:
Aria 2023-05-06 03:41:51 -07:00
parent 857d8eaf4a
commit bddc923eca
6 changed files with 98 additions and 4 deletions

View file

@ -1,6 +1,8 @@
package dev.zontreck.libzontreck.util;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BinUtil {
@ -21,6 +23,32 @@ public class BinUtil {
return new String(hexChars);
}
public static byte[] hexToBytes(String hexStr)
{
List<Byte> bList = new ArrayList<>();
for(int i=0;i<hexStr.length();i+=2)
{
bList.add((byte)(
(Character.digit(hexStr.charAt(i), 16)<<4) +
(Character.digit(hexStr.charAt(i+1), 16))
));
}
return byteArray(bList);
}
public static byte[] byteArray(List<Byte> b)
{
byte[] ret = new byte[b.size()];
int i=0;
for(byte bx : b)
{
ret[i] = bx;
i++;
}
return ret;
}
/**
* @return A random instance backed by the time including milliseconds as the seed.
*/

View file

@ -1,5 +1,7 @@
package dev.zontreck.libzontreck.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
import dev.zontreck.libzontreck.LibZontreck;
@ -74,6 +76,33 @@ public class ChatHelpers {
broadcastTo(ID.getUUID(), message, server, true);
}
public static String hashOfMd5(String input) throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("md5");
md5.update(input.getBytes());
return asHex(md5.digest());
}
public static String hashOfSha256(String input) throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("sha-256");
md5.update(input.getBytes());
return asHex(md5.digest());
}
public static String hashOfMd5(byte[] input) throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("md5");
md5.update(input);
return asHex(md5.digest());
}
public static String hashOfSha256(byte[] input) throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("sha-256");
md5.update(input);
return asHex(md5.digest());
}
public static String asHex(byte[] input)
{
return BinUtil.bytesToHex(input);
}
/**
* Returns the output with colors applied, and chat entries replaced using [number] as the format
* @param input