ToEncryptedString() public method

Returns a base 64 encrypted serialized representation of this object.
public ToEncryptedString ( ) : string
return string
示例#1
0
        public void CanRoundTripCaptchaInfo()
        {
            DateTime date = DateTime.ParseExact(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

            CaptchaInfo info = new CaptchaInfo("My Test");
            info.WarpFactor = CaptchaImage.FontWarpFactor.High;
            info.DateGenerated = date;

            string encrypted = info.ToEncryptedString();
            Assert.IsTrue(encrypted.IndexOf("My Test") < 0);
            info = CaptchaInfo.FromEncryptedString(encrypted);
            Assert.AreEqual("My Test", info.Text);
            Assert.AreEqual(CaptchaImage.FontWarpFactor.High, info.WarpFactor);
            Assert.AreEqual(date, info.DateGenerated);
        }
示例#2
0
        protected override void Render(HtmlTextWriter writer)
        {
            RenderHiddenInputForEncryptedAnswer(writer);
            writer.Write("<div id=\"{0}\"", ClientID);
            if (!String.IsNullOrEmpty(CssClass))
            {
                writer.Write(" class=\"{0}\"", CssClass);
            }
            else
            {
                writer.Write(" class=\"captcha\"");
            }
            writer.Write(">");

            string src = HttpHelper.ExpandTildePath("~/images/services/CaptchaImage.ashx");

            writer.Write("<img src=\"{0}", src);
            if (!IsDesignMode)
            {
                writer.Write("?spec={0}", HttpUtility.UrlEncodeUnicode(_captcha.ToEncryptedString()));
            }
            writer.Write("\" border=\"0\"");

            writer.Write(" width=\"{0}\" ", Width.Value);
            writer.Write(" height=\"{0}\" ", Height.Value);
            if (ToolTip.Length > 0)
            {
                writer.Write(" alt='{0}'", ToolTip);
            }
            writer.Write(" />");

            if (DefaultText.Length > 0)
            {
                writer.Write("<label for=\"{0}\">", AnswerFormFieldName);
                writer.Write(DefaultText);
                writer.Write("</label>");
                base.Render(writer);
            }

            writer.Write("<input name=\"{0}\" type=\"text\" size=\"", AnswerFormFieldName);
            writer.Write(_captcha.TextLength.ToString(CultureInfo.InvariantCulture));
            writer.Write("\" maxlength=\"{0}\"", _captcha.TextLength);
            if (AccessKey.Length > 0)
            {
                writer.Write(" accesskey=\"{0}\"", AccessKey);
            }
            if (!Enabled)
            {
                writer.Write(" disabled=\"disabled\"");
            }
            if (TabIndex > 0)
            {
                writer.Write(" tabindex=\"{0}\"", TabIndex);
            }
            if (Page.IsPostBack && IsValid)
            {
                writer.Write(" value=\"{0}\" />", HttpUtility.HtmlEncode(Page.Request.Form[AnswerFormFieldName]));
            }
            else
            {
                writer.Write(" value=\"\" />");
            }

            writer.Write("</div>");
        }