Пример #1
0
        public static void Execute(string choice)
        {
            var digest = new HmacDigest();

            byte[] inputBuffer = new byte[1024];
            Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);

            Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
            Console.SetBufferSize(128, 1024);
            if (choice == "1")
            {
                Console.WriteLine("Please enter text for Encrypt:");
                string inputText = Console.ReadLine();
                Console.WriteLine("\nEncryptKey:");
                CryptoAlgorithm settingsDecryptor = new CryptoAlgorithm("ENCRYPT", "FSCS", new AesManaged());
                var             value             = settingsDecryptor.Encrypt(inputText);
                Console.WriteLine(value);
            }
            else if (choice == "2")
            {
                Console.WriteLine("Public App Key: " + digest.PublicKey.ToString());
                Console.WriteLine("\nDigest: " + digest.HashedStringBase64);
                Console.WriteLine("\nEpoch Time: " + digest.EpochTime.ToString());
            }
            else if (choice == "3")
            {
                Console.WriteLine("Hit Enter to exit, Cya!!!");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Invalid Choice, Hit Enter to exit");
            }
        }
Пример #2
0
        public static HttpClient GetClient(HeaderType headerType)
        {
            HttpClient client = null;

            if (_httpClients.ContainsKey(headerType))
            {
                client = _httpClients[headerType];
            }
            else
            {
                lock (_httpClients)
                {
                    var handler = new HttpClientHandler();
                    handler.AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip;
                    client = new HttpClient(handler);
                    client.DefaultRequestHeaders.Add("Accept", "application/json");

                    switch (headerType)
                    {
                    case HeaderType.FSCMediation:
                        var digest = new HmacDigest();
                        client.DefaultRequestHeaders.Add("X-Level3-Application-Key", digest.PublicKey);
                        client.DefaultRequestHeaders.Add("X-Level3-Digest", digest.HashedStringBase64);
                        client.DefaultRequestHeaders.Add("X-Level3-Digest-Time", digest.EpochTime.ToString());
                        break;
                    }

                    // double check to make sure it wasn't added by another thread
                    if (!_httpClients.ContainsKey(headerType))
                    {
                        _httpClients.Add(headerType, client);
                    }
                }
            }
            return(client);
        }