OL.FrameCore.Infrastructure/Security/RSAHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Text;
namespace OL.FrameCore.Infrastructure.Security
{
/// <summary>
/// RSA加密解密帮助
/// </summary>
public class RSAHelper
{
static object obj = new object();
static RsaKeyPair CacheRsaKey;
static DateTime KeyTime;
/// <summary>
/// 获取公钥
/// </summary>
/// <returns></returns>
public static string GetPublic()
{
if (CacheRsaKey == null || KeyTime == null || DateTime.Now.Date > KeyTime.Date)
{
lock (obj)
{
//新密钥
var rsaKeyPair = RSAUtility.CreateKeyPair();
CacheRsaKey = new RsaKeyPair
{
PublicKey = rsaKeyPair.Item1,
PrivateKey = rsaKeyPair.Item2
};
KeyTime = DateTime.Now;
}
}
if (CacheRsaKey == null)
{
throw new Exception("密钥生成失败");
}
else
{
return CacheRsaKey.PublicKey;
}
}
/// <summary>
/// 获取私钥
/// </summary>
/// <returns></returns>
public static string GetPrivate()
{
if (CacheRsaKey == null)
{
throw new Exception("密钥未生成");
}
else
{
return CacheRsaKey.PrivateKey;
}
后面还有 29 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
