DotNet.Authorize/RSA/RSAKeyCreater.cs

(开头部分) 3KB

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

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace DotNet.Authorize
{
    public static class RSAKeyCreater
    {
        /// <summary>
        /// RSA算法的标准参数
        /// </summary>
        private static RSAParameters keys;

        /// <summary>
        /// 将指定文本创建到指定文件中
        /// </summary>
        /// <param name="text">指定文本</param>
        /// <param name="file">指定文件</param>
        private static void CreateFile(string text, string file)
        {
            file = file.Replace("/", "\\");
            string directory = file.Substring(0, file.LastIndexOf("\\"));
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            try
            {
                using (StreamWriter sw = new StreamWriter(file, false, System.Text.Encoding.UTF8))
                {
                    sw.Write(text);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("保存失败!请确认有无操作权限。", ex);
            }
        }

        /// <summary>
        /// 生成RSA密钥对
        /// </summary>
        /// <param name="xmlFilePublicKey">公钥文件</param>
        /// <param name="xmlFilePrivateKey">私钥文件</param>
        public static void CreateRSAKey(string xmlFilePublicKey, string xmlFilePrivateKey)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            keys = rsa.ExportParameters(true);

            _createPublicKeyFile(xmlFilePublicKey);
后面还有 33 行代码,购买后查看完整代码

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

AI 解读 AI

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

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