private static APIResultAuthorize Authenticate001(ISimpleJsonRest web, APIAuthParams apiparams, string mail, string uip, AlephLogger logger) { try { logger.Debug(StandardNotePlugin.Name, $"AuthParams[version:1, pw_func:{apiparams.pw_func}, pw_alg:{apiparams.pw_alg}, pw_cost:{apiparams.pw_cost}, pw_key_size:{apiparams.pw_key_size}]"); if (apiparams.pw_func != PasswordFunc.pbkdf2) { throw new Exception("Unsupported pw_func: " + apiparams.pw_func); } byte[] bytes; if (apiparams.pw_alg == PasswordAlg.sha512) { bytes = PBKDF2.GenerateDerivedKey(apiparams.pw_key_size / 8, Encoding.UTF8.GetBytes(uip), Encoding.UTF8.GetBytes(apiparams.pw_salt), apiparams.pw_cost, PBKDF2.HMACType.SHA512); } else if (apiparams.pw_alg == PasswordAlg.sha512) { bytes = PBKDF2.GenerateDerivedKey(apiparams.pw_key_size / 8, Encoding.UTF8.GetBytes(uip), Encoding.UTF8.GetBytes(apiparams.pw_salt), apiparams.pw_cost, PBKDF2.HMACType.SHA512); } else { throw new Exception("Unknown pw_alg: " + apiparams.pw_alg); } var pw = bytes.Take(bytes.Length / 2).ToArray(); var mk = bytes.Skip(bytes.Length / 2).ToArray(); var reqpw = EncodingConverter.ByteToHexBitFiddleUppercase(pw).ToLower(); APIResultAuthorize tok; try { tok = web.PostDownload <APIResultAuthorize>("auth/sign_in", "email=" + mail, "password="******"Server returned status {e1.StatusCode}.\nMessage: '{req.error.message}'", e1); } } throw; } tok.masterkey = mk; tok.version = "001"; return(tok); } catch (StandardNoteAPIException) { throw; } catch (RestException) { throw; } catch (Exception e) { throw new StandardNoteAPIException("Authentification with StandardNoteAPI failed.", e); } }