public static AnswerResponse criarAnswerJSON(int casas, string token, string cifrado, string decifrado, string resumoCriptografado) { var answerResponse = new AnswerResponse { NumeroCasas = casas, Token = token, Cifrado = cifrado, Decifrado = decifrado, ResumoCriptografado = resumoCriptografado }; return(answerResponse); }
static async Task Main(string[] args) { try { //url para envio GET var url = "https://api.codenation.dev/v1/challenge/dev-ps/generate-data?token=" + _TOKEN; var response = await client.GetAsync(url); // obter resposta da api var responseJson = await response.Content.ReadAsStringAsync(); // converte JSON response para Object AnswerResponse answer = JsonConvert.DeserializeObject <AnswerResponse>(responseJson); //string mensagemDecifrada = decifrarFrase("gwc kiv vmdmz cvlmzmabquibm bpm abcxqlqbg wn bpm omvmzit xcjtqk. akwbb iliua", 8); string mensagemDecifrada = decifrarFrase(answer.Cifrado, answer.NumeroCasas); //gerar SH1 UTF8Encoding enc = new UTF8Encoding(); byte[] buffer = enc.GetBytes(mensagemDecifrada); SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider(); string resumoSH1 = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "").ToLower(); //criar json var answerJSON = criarAnswerJSON(answer.NumeroCasas, answer.Token, answer.Cifrado, mensagemDecifrada, resumoSH1); var objJSON = JsonConvert.SerializeObject(answerJSON, Formatting.Indented); if (File.Exists("answer.json")) { File.Delete("answer.json"); } File.WriteAllText("answer.json", objJSON); //enviar answer.json enviaArquivoAsync(_TOKEN, "answer.json").Wait(); } catch (Exception e) { Console.WriteLine("Erro ao consumir API! Tente novamente. \n\n" + e); } }