boolean authenticate(LoginKeyCallback callback) {
sessionId = new BASE64Encoder().encode(String.valueOf(callback.getUniqueId()).getBytes());
Util.printConsole("Got login key, performing web auth...", this, ConsoleColor.Magenta, true);
final WebAPI userAuth = new WebAPI("ISteamUserAuth", BotInfo.getApiKey());
// generate an AES session key
final byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32);
// rsa encrypt it with the public key for the universe we're on
byte[] cryptedSessionKey = null;
final RSACrypto rsa = new RSACrypto(KeyDictionary.getPublicKey(steamClient.getConnectedUniverse()));
cryptedSessionKey = rsa.encrypt(sessionKey);
final byte[] loginKey = new byte[20];
System.arraycopy(callback.getLoginKey().getBytes(), 0, loginKey, 0, callback.getLoginKey().length());
// aes encrypt the loginkey with our session key
final byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);
KeyValue authResult;
try {
authResult = userAuth.authenticateUser(String.valueOf(steamClient.getSteamId().convertToLong()), WebHelpers.UrlEncode(cryptedSessionKey), WebHelpers.UrlEncode(cryptedLoginKey), "POST");
} catch (final Exception e) {
return false;
}
token = authResult.get("token").asString();