/// <summary> /// Login to Mega.co.nz service using hashed credentials /// </summary> /// <param name="authInfos">Authentication informations generated by <see cref="GenerateAuthInfos"/> method</param> /// <exception cref="ApiException">Service is not available or authInfos is invalid</exception> /// <exception cref="ArgumentNullException">authInfos is null</exception> /// <exception cref="NotSupportedException">Already logged in</exception> public LogonSessionToken Login(AuthInfos authInfos) { if (authInfos == null) { throw new ArgumentNullException("authInfos"); } this.EnsureLoggedOut(); this.authenticatedLogin = true; // Request Mega Api LoginRequest request = new LoginRequest(authInfos.Email, authInfos.Hash); LoginResponse response = this.Request <LoginResponse>(request); // Decrypt master key using our password key byte[] cryptedMasterKey = response.MasterKey.FromBase64(); this.masterKey = Crypto.DecryptKey(cryptedMasterKey, authInfos.PasswordAesKey); // Decrypt RSA private key using decrypted master key byte[] cryptedRsaPrivateKey = response.PrivateKey.FromBase64(); BigInteger[] rsaPrivateKeyComponents = Crypto.GetRsaPrivateKeyComponents(cryptedRsaPrivateKey, this.masterKey); // Decrypt session id byte[] encryptedSid = response.SessionId.FromBase64(); byte[] sid = Crypto.RsaDecrypt(encryptedSid.FromMPINumber(), rsaPrivateKeyComponents[0], rsaPrivateKeyComponents[1], rsaPrivateKeyComponents[2]); // Session id contains only the first 58 base64 characters this.sessionId = sid.ToBase64().Substring(0, 58); return(new LogonSessionToken(this.sessionId, this.masterKey)); }
/// <summary> /// Login to Mega.co.nz service using hashed credentials /// </summary> /// <param name="authInfos">Authentication informations generated by <see cref="GenerateAuthInfos"/> method</param> /// <exception cref="ApiException">Service is not available or authInfos is invalid</exception> /// <exception cref="ArgumentNullException">authInfos is null</exception> /// <exception cref="NotSupportedException">Already logged in</exception> public void Login(AuthInfos authInfos) { if (authInfos == null) { throw new ArgumentNullException("authInfos"); } this.EnsureLoggedOut(); // Store authInfos to relogin if required this._authInfos = authInfos; // Request Mega Api LoginRequest request = new LoginRequest(authInfos.Email, authInfos.Hash); LoginResponse response = this.Request <LoginResponse>(request); // Decrypt master key using our password key byte[] cryptedMasterKey = response.MasterKey.FromBase64(); this._masterKey = Crypto.DecryptKey(cryptedMasterKey, authInfos.PasswordAesKey); // Decrypt RSA private key using decrypted master key byte[] cryptedRsaPrivateKey = response.PrivateKey.FromBase64(); BigInteger[] rsaPrivateKeyComponents = Crypto.GetRsaPrivateKeyComponents(cryptedRsaPrivateKey, this._masterKey); // Decrypt session id byte[] encryptedSid = response.SessionId.FromBase64(); byte[] sid = Crypto.RsaDecrypt(encryptedSid.FromMPINumber(), rsaPrivateKeyComponents[0], rsaPrivateKeyComponents[1], rsaPrivateKeyComponents[2]); // Session id contains only the first 43 decrypted bytes this._sessionId = sid.CopySubArray(43).ToBase64(); }
public MegaApiClient Login() { MegaApiClient client = new MegaApiClient(); AuthInfos AI = JsonConvert.DeserializeObject <AuthInfos>(Constants.AuthInfoJsonString); client.Login(AI); return(client); }
/// <summary> /// Generates a JSON file with login encrypted data to use with Mega Api /// </summary> /// <returns>true if everything went ok</returns> public static bool GetAuthInfo() { try { MegaApiClient client = new MegaApiClient(); AuthInfos AU = MegaApiClient.GenerateAuthInfos("*****@*****.**", "password"); //Your email and pass used to create the mega account MegaApiClient.AuthInfos AF = AU; // = new MegaApiClient.AuthInfos() MessageBox.Show(AF.PasswordAesKey.ToString()); string json = JsonConvert.SerializeObject(AF); JObject Auth = (JObject)JToken.FromObject(AF); // write JSON directly to a file using (StreamWriter file = File.CreateText("C:/Auth.json")) //location where the json file is going to be saved using (JsonTextWriter writer = new JsonTextWriter(file)) { Auth.WriteTo(writer); } return(true); } catch { return(false); } }
public Task <LogonSessionToken> LoginAsync(AuthInfos authInfos) { return(Task.Run(() => this.Login(authInfos))); }
public Task LoginAsync(AuthInfos authInfos) { return(Task.Run(() => this.Login(authInfos))); }