예제 #1
0
        public string Decrypt(string text)
        {
            AESController aes = new AESController();

            if (aes.HasError())
            {
                return(aes.error);
            }

            return(aes.Decrypt(text));
        }
예제 #2
0
        public HttpResponseMessage GetQr(string text)
        {
            try
            {
                AESController aes = new AESController();

                if (aes.HasError())
                {
                    throw new Exception(aes.error);
                }

                string textoEncriptado = aes.Encrypt(text);

                if (aes.HasError())
                {
                    throw new Exception(aes.error);
                }

                string path      = HttpContext.Current.Server.MapPath("/qrcode.png");
                var    qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
                var    qrCode    = qrEncoder.Encode(textoEncriptado);

                var renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream);
                }

                var file = new FileStream(path, FileMode.Open, FileAccess.Read);

                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(file);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
                return(result);
            }
            catch (Exception ex)
            {
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.BadRequest);
                result.Content = new StringContent(ex.Message);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                return(result);
            }
        }
예제 #3
0
        private async void Scanner()
        {
            var scannerPage = new ZXingScannerPage();

            scannerPage.Title         = "Lector de QR";
            scannerPage.OnScanResult += (result) =>
            {
                scannerPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopAsync();
                    AESController aes = new AESController();

                    if (aes.HasError())
                    {
                        DisplayAlert("Error: ", aes.error, "OK");
                    }
                    else
                    {
                        string textDecrypt = aes.Decrypt(result.Text);

                        if (aes.HasError())
                        {
                            DisplayAlert("Se produjo un error:", textDecrypt, "OK");
                        }
                        else
                        {
                            DisplayAlert("Valor Obtenido", textDecrypt, "OK");
                        }
                    }
                });
            };

            await Navigation.PushAsync(scannerPage);
        }