/// <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)); }
// Token: 0x06000938 RID: 2360 RVA: 0x0004B5FC File Offset: 0x000497FC public MegaApiClient.LogonSessionToken Login(MegaApiClient.AuthInfos authInfos) { if (authInfos == null) { throw new ArgumentNullException("authInfos"); } this.EnsureLoggedOut(); this.authenticatedLogin = true; LoginRequest request; if (!string.IsNullOrEmpty(authInfos.MFAKey)) { request = new LoginRequest(authInfos.Email, authInfos.Hash, authInfos.MFAKey); } else { request = new LoginRequest(authInfos.Email, authInfos.Hash); } LoginResponse loginResponse = this.Request <LoginResponse>(request, null); byte[] data = loginResponse.MasterKey.FromBase64(); this.masterKey = Crypto.DecryptKey(data, authInfos.PasswordAesKey); BigInteger[] rsaPrivateKeyComponents = Crypto.GetRsaPrivateKeyComponents(loginResponse.PrivateKey.FromBase64(), this.masterKey); byte[] source = Crypto.RsaDecrypt(loginResponse.SessionId.FromBase64().FromMPINumber(), rsaPrivateKeyComponents[0], rsaPrivateKeyComponents[1], rsaPrivateKeyComponents[2]); this.sessionId = source.Take(43).ToArray <byte>().ToBase64(); return(new MegaApiClient.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(); }