Beispiel #1
0
        // Token: 0x06000932 RID: 2354 RVA: 0x0004B428 File Offset: 0x00049628
        public MegaApiClient.AuthInfos GenerateAuthInfos(string email, string password, string mfaKey = null)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException("email");
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }
            PreLoginRequest  request          = new PreLoginRequest(email);
            PreLoginResponse preLoginResponse = this.Request <PreLoginResponse>(request, null);

            if (preLoginResponse.Version == 2 && !string.IsNullOrEmpty(preLoginResponse.Salt))
            {
                byte[] salt      = preLoginResponse.Salt.FromBase64();
                byte[] password2 = password.ToBytesPassword();
                byte[] array     = new byte[32];
                using (HMACSHA512 hmacsha = new HMACSHA512())
                {
                    array = new Pbkdf2(hmacsha, password2, salt, 100000).GetBytes(array.Length);
                }
                if (!string.IsNullOrEmpty(mfaKey))
                {
                    return(new MegaApiClient.AuthInfos(email, array.Skip(16).ToArray <byte>().ToBase64(), array.Take(16).ToArray <byte>(), mfaKey));
                }
                return(new MegaApiClient.AuthInfos(email, array.Skip(16).ToArray <byte>().ToBase64(), array.Take(16).ToArray <byte>(), null));
            }
            else
            {
                if (preLoginResponse.Version != 1)
                {
                    throw new NotSupportedException("Version of account not supported");
                }
                byte[] passwordAesKey = MegaApiClient.PrepareKey(password.ToBytesPassword());
                string hash           = MegaApiClient.GenerateHash(email.ToLowerInvariant(), passwordAesKey);
                if (!string.IsNullOrEmpty(mfaKey))
                {
                    return(new MegaApiClient.AuthInfos(email, hash, passwordAesKey, mfaKey));
                }
                return(new MegaApiClient.AuthInfos(email, hash, passwordAesKey, null));
            }
        }