public TData Unprotect(string protectedText) { try { if (protectedText == null) { return(default(TData)); } byte[] protectedData = _encoder.Decode(protectedText); if (protectedData == null) { return(default(TData)); } byte[] userData = _protector.Unprotect(protectedData); if (userData == null) { return(default(TData)); } TData model = _serializer.Deserialize(userData); return(model); } catch { // TODO trace exception, but do not leak other information return(default(TData)); } }
private void Decode() { Do(() => { _decoded = _encoder.Decode(_encoded, CurrentEncoding, UrlEncode); OnPropertyChanged("Decoded"); }); }
public AuthenticationTicket Unprotect(string text) { var protectedData = _encoder.Decode(text); var ticketData = _protector.Unprotect(protectedData); var ticket = _serializer.Deserialize(ticketData); return(ticket); }
public void OwinDataHandler(ITextEncoder encoder, SecureDataFormat <AuthenticationProperties> secure) { AuthenticationProperties props = new AuthenticationProperties(); string secured = secure.Protect(props); AuthenticationProperties unsecured = secure.Unprotect(secured); byte[] decoded = new byte[10]; string encoded = encoder.Encode(decoded); decoded = encoder.Decode(encoded); }
public AuthenticationTicket Unprotect(string protectedText) { AuthenticationTicket ticket = null; try { var protectedData = encoder.Decode(protectedText); var serializedData = dataProtector.Unprotect(protectedData); ticket = serializer.Deserialize(serializedData); } catch (Exception ex) { logger.Error($"{DateTime.Now} {ex.Message}"); if (ex.InnerException?.Message != null) { logger.Error($"{DateTime.Now} {ex.InnerException.Message}"); } } return(ticket); }
public AuthenticationTicket Unprotect(string text) { AuthenticationTicket ticket = serializer.Deserialize(encoder.Decode(text)); return(ticket); }
public string SendMessage(MessageSendContainer msc) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(msc.SmtpAccountPerson_CompanyUse, msc.SmtpAccountEmailUse)); InternetAddressList addresses = new InternetAddressList(); bool yes = InternetAddressList.TryParse(ParserOptions.Default, msc.EmailAddressesTo, out addresses); if (!yes) { return($"Не отправлено (не указаны адресаты) письмо: '{msc.Subject}'"); } message.To.AddRange(addresses); message.Subject = msc.Subject; message.Body = new TextPart("plain") { Text = msc.Body }; try { using var client = new SmtpClient(); client.Connect(msc.SmtpServerUse, msc.PortUse, msc.SSLUse); client.Authenticate(msc.SmtpAccountEmailUse, _TextEncoder.Decode(msc.SmtpAccountPasswordUse)); client.Send(message); client.Disconnect(true); msc.Status = "2"; return($"отправлено адресатам."); } catch (ObjectDisposedException) { msc.Status = "0"; return($"не отправлено (утилизировано)."); } catch (ServiceNotConnectedException) { msc.Status = "0"; return($"не отправлено (ошибка соединения с сервером)."); } catch (ServiceNotAuthenticatedException) { msc.Status = "0"; return($"не отправлено (ошибка аутентификации)."); } catch (InvalidOperationException) { msc.Status = "0"; return($"не отправлено (не указан отправитель)."); } catch (OperationCanceledException) { msc.Status = "0"; return($"не отправлено (операция отменена)."); } catch (ProtocolException) { msc.Status = "0"; return($"не отправлено (ошибка отправки)."); } }