Beispiel #1
0
        public ReponseApi GetCodeMicrosoft(DataMicrosoft par)
        {
            ReponseApi      res         = new ReponseApi();
            QRFeatures      funciones   = new QRFeatures();
            QRCodeGenerator qrGenerator = new QRCodeGenerator();

            res.Codigo    = 0;
            res.Mensaje   = "";
            res.Respuesta = null;

            try
            {
                if (string.IsNullOrEmpty(par.Emisor))
                {
                    res.Mensaje = "El Emisor no puede ser nulo";
                }
                else if (string.IsNullOrEmpty(par.Cuenta))
                {
                    res.Mensaje = "La Cuenta no puede ser nula";
                }
                else
                {
                    ResponseQRMicrosoft resMicrosoft = new ResponseQRMicrosoft();

                    var        key              = TwoStepsAuthenticator.Authenticator.GenerateKey();
                    byte[]     inputBytes       = Encoding.ASCII.GetBytes(key);
                    string     base32           = Wiry.Base32.Base32Encoding.Standard.GetString(inputBytes);
                    string     codigoManual     = base32.Replace("=", null);
                    var        AuthenticatorUri = funciones.GenerateQrCodeUri(par.Cuenta, par.Emisor, key);
                    QRCodeData qrCodeData       = qrGenerator.CreateQrCode(AuthenticatorUri, QRCodeGenerator.ECCLevel.Q);


                    QRCode qrCode      = new QRCode(qrCodeData);
                    Bitmap qrCodeImage = qrCode.GetGraphic(4);

                    System.IO.MemoryStream ms = new MemoryStream();
                    qrCodeImage.Save(ms, ImageFormat.Png);
                    byte[] byteImage = ms.ToArray();
                    var    SigBase64 = Convert.ToBase64String(byteImage);

                    resMicrosoft.LlaveSecreta = key;
                    resMicrosoft.CodigoManual = codigoManual;
                    resMicrosoft.QRImagen     = "data:image/png;base64," + SigBase64;

                    res.Codigo    = 1;
                    res.Respuesta = resMicrosoft;
                }
            }
            catch (Exception ex)
            {
                //Log Error
                _logger.Log(LogLevel.Error, ex, ex.Message);
            }

            return(res);
        }
Beispiel #2
0
        public void PruevaGenerarQRMicrosoft()
        {
            TwoFactorController metodos        = new TwoFactorController();
            DataMicrosoft       datosMicrosoft = new DataMicrosoft();
            // Arrange
            int resultadoEsperado = 1;

            datosMicrosoft.Cuenta = "*****@*****.**";
            datosMicrosoft.Emisor = "SucursalDigital";
            //Act
            var resultadoCodigo = metodos.GetCodeMicrosoft(datosMicrosoft);

            // Assert
            Assert.Equals(resultadoEsperado, resultadoCodigo);
        }