src/ZKEACMS.Distribution/Service/CookieCaptchaCodeProvider.cs
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Easy.Extend;
using Easy.Mvc.ValueProvider;
using Microsoft.AspNetCore.DataProtection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZKEACMS.Captcha;
namespace ZKEACMS.Distribution.Service
{
public class CookieCaptchaCodeProvider : ICaptchaCodeStorageProvider
{
private readonly ICookie _cookie;
private readonly IDataProtector dataProtector;
private const string CookieName = "zkdiscap";
public CookieCaptchaCodeProvider(ICookie cookie, IDataProtectionProvider dataProtectionProvider)
{
_cookie = cookie;
dataProtector = dataProtectionProvider.CreateProtector("ImageCaptcha");
}
public string GetCode()
{
string code = _cookie.GetValue<string>(CookieName);
if (code.IsNotNullAndWhiteSpace())
{
try
{
return dataProtector.Unprotect(Base64StringDecode(code));
}
catch
{
return string.Empty;
}
}
return string.Empty;
}
public void SaveCode(string code)
{
string protectedCode = dataProtector.Protect(code);
_cookie.SetValue(CookieName, Base64StringEncode(protectedCode), true, true);
}
public string Base64StringEncode(string originalString)
{
var bytes = Encoding.UTF8.GetBytes(originalString);
var encodedString = Convert.ToBase64String(bytes);
return encodedString;
}
public string Base64StringDecode(string encodedString)
后面还有 9 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。