Beispiel #1
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            string data = "";

            // Get information wiht my token
            try
            {
                WebRequest request  = WebRequest.Create("https://api.codenation.dev/v1/challenge/dev-ps/generate-data?token=5fe5322db44b1c301caa43551e71a0d495620f71");
                var        response = request.GetResponse();
                using (Stream dataStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(dataStream);
                    data = reader.ReadToEnd();
                }
            }
            catch (Exception)
            {
            }

            // Parsing
            var resultado = JsonConvert.DeserializeObject <Answer>(data);

            // Decrypt
            resultado.decifrado = DecryptJulioCesar(1, resultado.cifrado);

            // SHA1
            resultado.resumo_criptografico = HashSha1.Hash(resultado.decifrado);

            // Show data
            Console.WriteLine("Cifrado = {0}", resultado.cifrado);
            Console.WriteLine("Decifrado = {0}", resultado.decifrado);
            Console.WriteLine("Decifrado = {0}", resultado.resumo_criptografico);


            // Generate temp file
            string filePath = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".json";

            File.WriteAllText(filePath, JsonConvert.SerializeObject(resultado));

            // Post data with multipart/form-data
            using (var httpClient = new HttpClient())
                using (var form = new MultipartFormDataContent())
                    using (var fs = File.OpenRead(filePath))
                        using (var streamContent = new StreamContent(fs))
                            using (var fileContent = new ByteArrayContent(await streamContent.ReadAsByteArrayAsync()))
                            {
                                fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
                                form.Add(fileContent, "answer", Path.GetFileName(filePath));
                                HttpResponseMessage response = await httpClient.PostAsync("https://api.codenation.dev/v1/challenge/dev-ps/submit-solution?token=5fe5322db44b1c301caa43551e71a0d495620f71", form);

                                data = await response.Content.ReadAsStringAsync();
                            }

            Console.WriteLine("Post Result = {0}", data);
            Console.ReadKey();
        }
Beispiel #2
0
        public void TestingUserIdWithoutInterval()
        {
            string secret = "SomeKey";

            byte[] key = Encoding.UTF8.GetBytes(secret);

            var             hmacSha1  = new HashSha1();
            OneTimePassword generator = new OneTimePassword(key, hmacSha1);
            String          otp       = generator.Generate("user", 0);

            Assert.AreEqual(OneTimePassword.MAXIMUM_DIGITS, otp.Length);
            Assert.AreEqual("31249860", otp);
        }
Beispiel #3
0
        public void TestingSha1()
        {
            string secret = "SomeKey";

            byte[] key          = Encoding.UTF8.GetBytes(secret);
            long   interval     = 66778;
            int    returnDigits = 6;

            var             hmacSha   = new HashSha1();
            OneTimePassword generator = new OneTimePassword(key, hmacSha, returnDigits);
            String          otp       = generator.Generate("12345", interval);

            Assert.IsNotNull(otp);
            Assert.AreEqual(6, otp.Length);
            Assert.AreEqual("337162", otp);
        }