void OnLoginKey(SteamUser.LoginKeyCallback callback) { string SessionID = WebHelpers.EncodeBase64(callback.UniqueID.ToString()); using (dynamic userAuth = WebAPI.GetInterface("ISteamUserAuth")) { // generate an AES session key var sessionKey = CryptoHelper.GenerateRandomBlock(32); // rsa encrypt it with the public key for the universe we're on byte[] cryptedSessionKey = null; using (var rsa = new RSACrypto(KeyDictionary.GetPublicKey(Client.ConnectedUniverse))) { cryptedSessionKey = rsa.Encrypt(sessionKey); } byte[] loginKey = new byte[20]; Array.Copy(Encoding.ASCII.GetBytes(callback.LoginKey), loginKey, callback.LoginKey.Length); // AES encrypt the loginkey with our session key. byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey); KeyValue authResult = null; EResult result = EResult.OK; try { authResult = userAuth.AuthenticateUser( steamid: Client.SteamID.ConvertToUInt64(), sessionkey: WebHelpers.UrlEncode(cryptedSessionKey), encrypted_loginkey: WebHelpers.UrlEncode(cryptedLoginKey), method: "POST" ); } catch (Exception) { result = EResult.Fail; } Login.SessionId = SessionID; if (authResult != null) { Login.Token = authResult["token"].AsString(); } this.Client.PostCallback(new WebLoggedOnCallback() { Result = result, Login = Login }); } }
/// <summary> /// Performs a login via the Steam web service API. /// </summary> public void LogOn(SteamUser.LoginKeyCallback details) { OnLoginKey(details); }