Yuebon.NetCore/Yuebon.Commons/Encrypt/RSASecurityHelper.cs

(开头部分) 10KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/*******************************************************************************
 * Copyright © 2017-2020 Yuebon.Framework 版权所有
 * Author: Yuebon
 * Description: Yuebon快速开发平台
 * Website:http://www.yuebon.com
*********************************************************************************/
using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace Yuebon.Commons.Encrypt
{
    /// <summary>
    /// 非对称加密、解密、验证辅助类
    /// </summary>
    public class RSASecurityHelper
    {

        /// <summary>
        /// 默认公钥。必须是8位字符的密钥字符串(不能有特殊字符)
        /// </summary>
        private const string DESENCRYPT_KEY = "yuebon.com";


        /// <summary>
        /// 非对称加密生成的私钥和公钥 
        /// </summary>
        /// <param name="publicKey">公钥,必须是8位字符的密钥字符串(不能有特殊字符)</param>
        /// <param name="privateKey">私钥</param>
        public static void GenerateRSAKey(out string privateKey, out string publicKey)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            privateKey = rsa.ToXmlString(true);
            publicKey = rsa.ToXmlString(false);
        }

        #region 非对称数据加密(公钥加密)
        /// <summary>
        ///  非对称加密字符串数据,返回加密后的数据
        /// </summary>
        /// <param name="originalString">待加密的字符串</param>
        /// <returns></returns>
        public static string RSAEncrypt(string originalString)
        {
            return RSAEncrypt(originalString, DESENCRYPT_KEY);
        }

        /// <summary>
        /// 非对称加密字节数组,返回加密后的数据
        /// </summary>
        /// <param name="originalBytes">待加密的字节数组</param>
        public static string RSAEncrypt(byte[] originalBytes)
        {
            return RSAEncrypt(originalBytes, DESENCRYPT_KEY);
        }
        /// <summary>
        /// 非对称加密字符串数据,返回加密后的数据
        /// </summary>
        /// <param name="originalString">待加密的字符串</param>
后面还有 205 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。