Exemple #1
0
        static void Main(string[] args)
        {
            RSAEncryptor rSA = new RSAEncryptor();

            Console.WriteLine("Escribe el string a cifrar");
            string text = Console.ReadLine();

            Console.WriteLine("Escribe la llave p");
            string p = Console.ReadLine();

            Console.WriteLine("Escribe la llave q");
            string q = Console.ReadLine();

            Console.WriteLine("Se ha guardado el string con éxito para cifrar");
            Console.WriteLine("El resultado del cifrado es el siguiente:");
            text = rSA.EncryptString(Convert.ToInt32(p), Convert.ToInt32(q), text);
            Console.WriteLine(text);
            Console.WriteLine("¿Desea descifrarlo? | Presione 'Y'. De lo contrario, presione cualquier otra tecla.");
            if (Console.ReadKey().Key == ConsoleKey.Y)
            {
                Console.Clear();
                Console.WriteLine("El resultado del descifrado es el siguiente:");
                Console.WriteLine(rSA.DecryptString(text));
                Console.ReadLine();
            }
            Console.WriteLine("Feliz día!");
            Console.ReadLine();
        }
Exemple #2
0
        static async Task <string> AuthenticateAsync()
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri("https://localhost:44321/api/v1/");

            var rsaKeyResponse = await client.GetAsync("security/public-key/rsa");

            var rsaKeyStr = await rsaKeyResponse.Content.ReadAsStringAsync();

            RSAEncryptor.ImportPublicKeyPKCS1(rsaKeyStr);

            var username = "******";
            var password = "******";

            password = RSAEncryptor.EncryptString(password);

            var response = await client.PostAsync(
                "account/login",
                new StringContent(JsonConvert.SerializeObject(new { username, password }), Encoding.UTF8, "application/json"));

            var responseStr = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <JToken>(responseStr);

            return(result["jwt"].Value <string>());
        }