ZHJA_HJGL/HJGL_ZH/BLL/Common/Migrated/GetKey.cs

52 lines
1.4 KiB
C#
Raw Normal View History

2024-05-08 17:17:11 +08:00
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.IO;
/// <summary>
/// Summary description for RsaInfo
/// </summary>
public class GetKey
{
public GetKey()
{
//
// TODO: Add constructor logic here
//
}
public static void GetKeyFunction()
{
string keyFileName = System.Web.HttpContext.Current.Server.MapPath("~/MyXml/");
const int keySize = 1024;
RSACryptoServiceProvider sp = new RSACryptoServiceProvider(keySize);
string str = sp.ToXmlString(true);
string KeyXml = Guid.NewGuid().ToString();
System.Web.HttpContext.Current.Session["key"] = KeyXml;
TextWriter writer = new StreamWriter(keyFileName + KeyXml + "private.xml");
writer.Write(str);
writer.Close();
str = sp.ToXmlString(false);
writer = new StreamWriter(keyFileName + KeyXml + "public.xml");
writer.Write(str);
writer.Close();
}
public static void GetKeyFunctionAsSession()
{
const int keySize = 1024;
RSACryptoServiceProvider sp = new RSACryptoServiceProvider(keySize);
System.Web.HttpContext.Current.Session["keys"] = sp.ToXmlString(true);
}
}