public ActionResult GetImageBytes(string code)
        {
            try
            {
                var protectedTokenBytes = Convert.FromBase64String(code);
                var tokenBytes          = MachineKey.Unprotect(protectedTokenBytes, typeof(CaptchaImageToken).Name);
                var token = CaptchaImageToken.FromBytes(tokenBytes);

                if (!CheckGetImageBytesTimeout(token.Timestamp))
                {
                    return(InvalidCaptchaParamImage());
                }

                var image = new CaptchaImage();
                ApplyCaptchaImageProperties(image);

                image.Text = token.ImageContent;

                var resultStream = new MemoryStream();
                using (Bitmap bitmap = image.RenderImage())
                    bitmap.Save(resultStream, ImageFormat.Jpeg);

                return(File(resultStream.ToArray(), "image/jpeg"));
            }
            catch (Exception)
            {
                return(InvalidCaptchaParamImage());
            }
        }
        public ActionResult ViewImage()
        {
            var token = new CaptchaImageToken(GenerateRandomText());
            var protectedTokenBytes  = MachineKey.Protect(token.ToBytes(), typeof(CaptchaImageToken).Name);
            var protectedTokenString = Convert.ToBase64String(protectedTokenBytes);

            return(PartialView((object)protectedTokenString));
        }
        public static CaptchaImageToken FromBytes(byte[] bytes)
        {
            if (bytes == null || bytes.Length <= 8)
            {
                return(null);
            }

            var result = new CaptchaImageToken
            {
                Timestamp    = BitConverter.ToInt64(bytes, 0),
                ImageContent = Encoding.UTF8.GetString(bytes, 8, bytes.Length - 8)
            };

            return(result);
        }