Skip to content

Instantly share code, notes, and snippets.

@Sonereign
Created November 21, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Sonereign/a3398083d13ce8f147a49d32c6aeeda0 to your computer and use it in GitHub Desktop.
Save Sonereign/a3398083d13ce8f147a49d32c6aeeda0 to your computer and use it in GitHub Desktop.
import l2e.commons.util.Base64;
import l2e.commons.util.Functions;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class KeyGenerator
{
private static String _key = "";
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException
{
// Check server.ini, find field UserName and set your desired UserName in server.ini (dont forget to update it here)
applyKey("REPLACE_ME_WITH_NEW_USER_NAME_FROM_SERVER_INI_IN_CONFIGS", "127.0.0.1");
System.out.println("The valid key for the given User Name and External Host is: " + _key);
}
private static String getBufferKey(String s)
{
try
{
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(s.getBytes());
StringBuilder hexString = new StringBuilder();
byte[] byteData = md.digest();
for (byte aByteData : byteData)
{
String hex = Integer.toHexString(0xFF & aByteData);
if (hex.length() == 1)
hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
}
catch (Exception exception)
{
return null;
}
}
private static void getGenerateByte(String s, String s1, String s2)
{
try
{
String finalKey = s2 + s + s2 + s1;
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] raw = finalKey.getBytes(StandardCharsets.UTF_8);
byte[] hash = md.digest(raw);
_key = Base64.encodeBytes(hash);
Functions.setBuffKey(_key);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void applyKey(String configUserName, String EXTERNAL_HOSTNAME)
{
try
{
String toEncrypt = System.getenv("COMPUTERNAME") + System.getProperty("user.name") + System.getenv("PROCESSOR_IDENTIFIER") + System.getenv("PROCESSOR_LEVEL");
String pcKey = getBufferKey(toEncrypt);
getGenerateByte(pcKey, getBufferKey(configUserName), getBufferKey(EXTERNAL_HOSTNAME));
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment