Пример #1
0
 public string GetPublicKey()
 {
     AccountCreation ac = new AccountCreation();
     ac.pubKey = Encryption.GetPubKey();
     ac.message = new byte[0];
     return ac.ToString();
 }
Пример #2
0
        public static bool CreateAccount(string userName, string password)
        {
            AccountCreation ac;
            try
            {
                string wrURI = baseServerTarget + "getpublickey";
                WebRequest wreq = WebRequest.Create(wrURI);
                WebResponse wresp = wreq.GetResponse();
                using (StreamReader sr = new StreamReader(wresp.GetResponseStream()))
                {
                    XmlSerializer rsa = new XmlSerializer(typeof(string), StringNamespace);
                    string resp = (string)rsa.Deserialize(sr);
                    ac = new AccountCreation(resp);
                }
            }
            catch
            {
                return false;
            }

            // Not meant as encryption, but at least makes sure that the text we
            // save on the server isn't an actual password.
            password = Encryption.GetSha256Hash(password);
            ac.message = Encryption.Encrypt(String.Format("{0}\n{1}", userName, password), ac.pubKey);

            try
            {
                string wrURI = baseServerTarget + "createaccount";
                string msg = ac.ToString();
                WebRequest wreq = WebRequest.Create(wrURI + "?message=" + msg);
                wreq.Method = "POST";
                wreq.ContentLength = 0;
                WebResponse wresp = wreq.GetResponse();
                using (TextReader sr = new StreamReader(wresp.GetResponseStream()))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(bool), StringNamespace);
                    bool resp = (bool)xml.Deserialize(sr);
                    return resp;
                }

            }
            catch
            {
                return false;
            }
        }