private string EncryptPassword(RsaParameters rsaParam) { // Convert the public keys to BigIntegers var modulus = CreateBigInteger(rsaParam.Modulus); var exponent = CreateBigInteger(rsaParam.Exponent); // (modulus.ToByteArray().Length - 1) * 8 //modulus has 256 bytes multiplied by 8 bits equals 2048 var encryptedNumber = Pkcs1Pad2(rsaParam.Password, (2048 + 7) >> 3); // And now, the RSA encryption encryptedNumber = BigInteger.ModPow(encryptedNumber, exponent, modulus); //Reverse number and convert to base64 var encryptedString = Convert.ToBase64String(encryptedNumber.ToByteArray().Reverse().ToArray()); return(encryptedString); }
public async void Login(string pUsername, string pPassword) { Console.WriteLine("Steamcommunity Login"); //Get RSA Dictionary <string, string> data = new Dictionary <string, string>(); var request = await m_HttpClient.GetAsync(STEAM_COMMUNITY_GETRSA + "?username="******"Unsuccessfull RSA Key request."); return; } RsaParameters rsaParam = new RsaParameters { Exponent = rsaKey.publickey_exp, Modulus = rsaKey.publickey_mod, Password = pPassword }; var encrypted = string.Empty; while (encrypted.Length < 2 || encrypted.Substring(encrypted.Length - 2) != "==") { encrypted = EncryptPassword(rsaParam); } data.Add("username", pUsername); data.Add("password", encrypted); data.Add("twofactorcode", ""); data.Add("emailauth", ""); data.Add("loginfriendlyname", ""); data.Add("captchagid", "-1"); data.Add("captcha_text", ""); data.Add("emailsteamid", ""); data.Add("rsatimestamp", rsaKey.timestamp); data.Add("remember_login", "false"); request = await m_HttpClient.PostAsync(STEAM_COMMUNITY_LOGIN, new FormUrlEncodedContent(data)); result = await request.Content.ReadAsStringAsync(); LoginResult loginResult = JsonConvert.DeserializeObject <LoginResult>(result); if (loginResult.success) { IEnumerable <Cookie> responseCookies = m_CookieContainer.GetCookies(new Uri(STEAM_COMMUNITY)).Cast <Cookie>(); foreach (var cookie in responseCookies) { Console.WriteLine("Name {0}, {1}", cookie.Name, cookie.Value); } Console.WriteLine("Successfully logged in."); loginSuccess = true; //SendCookies } else { Console.WriteLine("Couldn't login..."); Console.WriteLine(result); } }