Skip to content

Instantly share code, notes, and snippets.

@rogermb
Created December 27, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogermb/ddfd8490a95e023750fd21053c759035 to your computer and use it in GitHub Desktop.
Save rogermb/ddfd8490a95e023750fd21053c759035 to your computer and use it in GitHub Desktop.
TS3 channel password hashing algorithm in Java
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
public final class ChannelPasswordTest {
private static final String PASSWORD = "Testificate";
private static final String KEYPAIR = "MG0DAgeAAgEgAiBHF7Me8LnrIDDDs+M+7HzWOB6GlVBCICOD82dH3q1LDQIgGP2zYHxKbvA7NvCk2sLXr3k/+fHR+RNNGaNaUCPZ0jQCIAOR+91qkDvwc3nZ7yTrVwPBMaoynnqb5AP1x2HWpIP9";
private static final String TARGET = "2YalQTjyjAY728jPorU9A36YLEI=";
private static final Base64.Encoder B_64_ENCODER = Base64.getEncoder();
public static void main(String[] args) {
byte[] pwdHash = sha1Digest(PASSWORD.getBytes(StandardCharsets.UTF_8));
String pwdBase64 = B_64_ENCODER.encodeToString(pwdHash);
String joined = pwdBase64 + KEYPAIR;
byte[] joinedHash = sha1Digest(joined.getBytes(StandardCharsets.UTF_8));
String joinedBase64 = B_64_ENCODER.encodeToString(joinedHash);
System.out.println("EXPECTED: " + TARGET);
System.out.println("ACTUAL: " + joinedBase64);
/*
* Output:
* EXPECTED: 2YalQTjyjAY728jPorU9A36YLEI=
* ACTUAL: 2YalQTjyjAY728jPorU9A36YLEI=
*/
}
private static byte[] sha1Digest(byte[] input) {
try {
return MessageDigest.getInstance("SHA-1").digest(input);
} catch (NoSuchAlgorithmException e) {
System.err.println("Error: Your computer doesn't support SHA-1 (O.o)");
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment