Пример #1
0
 public RSAKeyLoader(string path)
 {
     using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
     {
         RsaKey curkey = new RsaKey();
         while (!reader.EndOfStream)
         {
             string line    = reader.ReadLine();
             Match  linereg = Regex.Match(line, @"(.*)[\s]?[:][\s]?(.*)");
             if (linereg.Success)
             {
                 if (linereg.Groups[1].Value == "n")
                 {
                     curkey.n = linereg.Groups[2].Value;
                 }
                 else if (linereg.Groups[1].Value == "d")
                 {
                     curkey.d = linereg.Groups[2].Value;
                 }
                 else if (linereg.Groups[1].Value == "e")
                 {
                     curkey.e = linereg.Groups[2].Value;
                 }
                 else
                 {
                 }
             }
             else
             {
                 RsaKeys.Add(curkey);
                 curkey = new RsaKey();
             }
         }
     }
 }
Пример #2
0
        private string CreateSession(string client_ip)
        {
            string sid = "";

            while (true)
            {
                sid = CreateRandomString(16);
                if (!SN.Sessions.Current.ContainsKey(sid))
                {
                    SN.Sessions.Current[sid] = new System.Collections.Generic.Dictionary <string, dynamic>();
                    SN.Sessions.Current[sid]["session.activationdate"] = DateTime.Now;
                    SN.Sessions.Current[sid]["session.clientip"]       = client_ip;
                    SN.Sessions.Current[sid]["session.authflag"]       = true;
                    RSA    rsa = new RSA(RsaLength, false, true);
                    RsaKey key = keyloader.GetKey();

                    rsa.SetPrivateKey(new rsa_component.PrivateKey()
                    {
                        d = key.d, n = key.n
                    });
                    rsa.SetPublicKey(new rsa_component.PublicKey()
                    {
                        e = key.e, n = key.n
                    });

                    SN.Sessions.Current[sid]["RSA"] = rsa;


                    break;
                }
            }
            return(sid);
        }