public async Task <string> Handle(Command request, CancellationToken cancellationToken) { request.UserName = _zCryptography.GetPlainText(request.UserName); request.Password = _zCryptography.GetPlainText(request.Password); string buffer = $"{ZTag.ZTAG_I_CMDEVT}SOLOLOGIN{ZTag.ZTAG_F_CMDEVT}{ZTag.ZTAG_I_USUARIO}{request.UserName}{ZTag.ZTAG_F_USUARIO}{ZTag.ZTAG_I_VALORCAMPO}{request.Password}{ZTag.ZTAG_F_VALORCAMPO}"; var result = _zsck.ExecuteCommand(new ZCommandDTO() { Buffer = buffer, Cmd = ZCommandConst.CM_SOLOLOGIN }); ZSoloLoginResponse zLoginResponse = _zsck.DeserializeXMLToObject <ZSoloLoginResponse>(result.Eventos.ElementAt(0).Dato.Buffer.Dato); if (zLoginResponse.MessageCode == ZSocket.ZSCK_ERROPERNOVAL) { throw new UnauthorizedAccessException(zLoginResponse.Message); } string token = _authService.GenerateJwtToken(new ZClaims { Tkna = zLoginResponse.Tkna }); return(token); }
public async Task <string> Handle(Command request, CancellationToken cancellationToken) { request.Buffer = _zCryptography.GetPlainText(request.Buffer); switch (request.Cmd) { case ZCommandConst.CM_ACEPTARLOGIN: // Retorna tkna return(await _mediator.Send(new AceptarLogin.Command(request))); case ZCommandConst.CM_APLICACION: return(await _mediator.Send(new Aplicacion.Command(request))); case ZCommandConst.CM_DEFMENU: case ZCommandConst.CM_EJECOPCION: // opcion de menu desplegado case ZCommandConst.CM_IRVENTANA_CS: return(_zSocket.EjecutarEvento(2, 0, request.Cmd, request.Buffer, "", request.IdAplication, request.Port, request.TokenJWT)); case ZCommandConst.CM_EJECSOLOOPCION: { var(result, tkns) = _zSocket.EjecutarSoloOpcion(request.IdAplication, request.Opcion, request.Buffer, null, request.Log, request.Tkna, request.RemoteIpAddress); string tokenJWT = _authService.GenerateJwtToken(new ZClaims { Tkna = request.Tkna, Tkns = tkns }); return(result.Replace($"<{ZTag.ZTAG_TKNS}>{tkns}</{ZTag.ZTAG_TKNS}>", $"<{ZTag.ZTAG_TKNS}>{tokenJWT}</{ZTag.ZTAG_TKNS}>")); } default: return(_zSocket.EjecutarEvento(2, 0, request.Cmd, "", request.Buffer, request.IdAplication, request.Port, request.TokenJWT)); } }
public void Plain_text_to_cipher_and_visceversa_works_well() { var plainText = "1234"; ZCryptographySettings zCriptographySettings = new ZCryptographySettings(); zCriptographySettings.Key = "$B&E)H@McQfTjWnZr4u7x!A%C*F-JaNd"; zCriptographySettings.IV = "z%C*F-JaNdRgUkXp"; /* * zCriptographySettings.Key = "$B&E)H@McQfTjWnZr4u7x!A%C*F-JaNd"; * zCriptographySettings.IV = "z%C*F-JaNdRgUkXp"; */ IOptions <ZCryptographySettings> settingsOptions = Options.Create(zCriptographySettings); ZCryptography zCriptography = new ZCryptography(settingsOptions); var cipherText = zCriptography.GetCipherText(plainText); var plainTextReversed = zCriptography.GetPlainText(cipherText); Assert.Equal(plainText, plainTextReversed); }