You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <summary>/// Login to Mega.co.nz service using email/password credentials/// </summary>/// <param name="email">email</param>/// <param name="password">password</param>/// <exception cref="ApiException">Service is not available or credentials are invalid</exception>/// <exception cref="ArgumentNullException">email or password is null</exception>/// <exception cref="NotSupportedException">Already logged in</exception>publicLogonSessionTokenLogin(stringemail,stringpassword){returnLogin(GenerateAuthInfos(email,password));}
GenerateAuthInfos
publicAuthInfosGenerateAuthInfos(stringemail,stringpassword,stringmfaKey=null){if(string.IsNullOrEmpty(email)){thrownewArgumentNullException("email");}if(string.IsNullOrEmpty(password)){thrownewArgumentNullException("password");}// Prelogin to retrieve account versionvarpreLoginRequest=newPreLoginRequest(email);varpreLoginResponse=Request<PreLoginResponse>(preLoginRequest);if(preLoginResponse.Version==2&&!string.IsNullOrEmpty(preLoginResponse.Salt)){// Mega uses a new way to hash password based on a salt sent by Mega during preloginvarsaltBytes=preLoginResponse.Salt.FromBase64();varpasswordBytes=password.ToBytesPassword();constintIterations=100000;varderivedKeyBytes=newbyte[32];using(varhmac=newHMACSHA512()){varpbkdf2=newPbkdf2(hmac,passwordBytes,saltBytes,Iterations);derivedKeyBytes=pbkdf2.GetBytes(derivedKeyBytes.Length);}// Derived key contains master key (0-16) and password hash (16-32)if(!string.IsNullOrEmpty(mfaKey)){returnnewAuthInfos(email,derivedKeyBytes.Skip(16).ToArray().ToBase64(),derivedKeyBytes.Take(16).ToArray(),mfaKey);}returnnewAuthInfos(email,derivedKeyBytes.Skip(16).ToArray().ToBase64(),derivedKeyBytes.Take(16).ToArray());}elseif(preLoginResponse.Version==1){// Retrieve password as UTF8 byte arrayvarpasswordBytes=password.ToBytesPassword();// Encrypt password to use password as key for the hashvarpasswordAesKey=PrepareKey(passwordBytes);// Hash email and password to decrypt master key on Mega serversvarhash=GenerateHash(email.ToLowerInvariant(),passwordAesKey);if(!string.IsNullOrEmpty(mfaKey)){returnnewAuthInfos(email,hash,passwordAesKey,mfaKey);}returnnewAuthInfos(email,hash,passwordAesKey);}else{thrownewNotSupportedException("Version of account not supported");}}
PrepareKey, AuthInfos, PreLoginRequest can easily be found in the SDK