Пример #1
0
        /// <summary>
        /// PLAIN authentication (RFC 2595)
        /// </summary>
        /// <param name="username">Username (e.g.: [email protected])</param>
        /// <param name="password">Password</param>
        /// <returns></returns>
        public string PLAIN(string username, string password)
        {
            var plain = new StringBuilder();

            plain.Append((char)0);
            plain.Append(username);
            plain.Append((char)0);
            plain.Append(password);
            return(base64.Encode(plain.ToString()));
        }
Пример #2
0
        //---------------------------------------------------------------------
        protected BaseBenchmark(IBase64?encoder)
        {
            _encoder = encoder ?? throw new ArgumentNullException(nameof(encoder));

            var random = new Random(42);

            _data = new byte[ByteArraySize];
            random.NextBytes(_data);
            _dataEncoded = _encoder.Encode(_data);

            _guid        = Guid.NewGuid().ToByteArray();
            _guidEncoded = _encoder.Encode(_guid);
        }
Пример #3
0
        public void Send(string sender, string recipient, string carbonCopy, string blindCarbonCopy, MailHeader[] myHeaders, string subject, string body)
        {
            CheckParameter(sender, nameof(sender));
            CheckParameter(recipient, nameof(recipient));
            headers = myHeaders;
            mail    = new MailMessage(sender, recipient);
            if (!string.IsNullOrEmpty(carbonCopy))
            {
                mail.CC.Add(carbonCopy);
            }
            if (!string.IsNullOrEmpty(blindCarbonCopy))
            {
                mail.Bcc.Add(blindCarbonCopy);
            }
            mail.SubjectEncoding = Encoding.UTF8;
            mail.BodyEncoding    = mail.SubjectEncoding;
            if (myHeaders != null)
            {
                foreach (var myHeader in myHeaders)
                {
                    try
                    {
                        if (myHeader.Name != String.Empty && myHeader.Value != String.Empty)
                        {
                            mail.Headers.Add(base64.Encode(myHeader.Name), base64.Encode(myHeader.Value));
                        }
                    }
                    catch { }
                }
            }

            mail.Subject = subject;
            mail.Body    = body;

            try
            {
                // NTLM (NT LAN Manager) Authentication /SMTP Extension/ throws System.FormatException - Invalid length for a Base-64 char array.
                if (ForceSmtpAuthentication)
                {
                    ForceSmtpClientAuthentication();
                }

                smtpClient.SendAsync(mail, null); //this.smtpClient.Send(mail);
            }
            catch (Exception ex)
            {
                OnSentChanged(new SentChangedEventArgs(false, headers, ex, Arguments));
            }
        }
Пример #4
0
 public string Encode_Data() => _encoder.Encode(_data.AsSpan());                                 // AsSpan for .NET Full
Пример #5
0
        public void TestVectorsFromRFC4648_should_encode_successfully(string original, string encoding)
        {
            var encoded = _base64.Encode(Encoding.ASCII.GetBytes(original));

            encoded.Should().Be(encoding);
        }
Пример #6
0
 public string Encode_Data() => _encoder.Encode(_data);