/// <summary> /// Helper method to sign members up. Writes information to XML. /// Called upon correct user input of account creation. /// </summary> private void signup() { int i; string[] data = new string[4]; byte[] encrypted; string strEncrypted = ""; string key = ""; string iv = ""; data[0] = txt_username.Text; Aes aesAlg = Aes.Create(); // store key for de-cryption for (i = 0; i < aesAlg.Key.Length - 1; i++) { key += aesAlg.Key[i].ToString() + ","; } key += aesAlg.Key[i].ToString(); data[2] = key; // store iv for de-cryption for (i = 0; i < aesAlg.IV.Length - 1; i++) { iv += aesAlg.IV[i].ToString() + ","; } iv += aesAlg.IV[i].ToString(); data[3] = iv; // Encrypt using (aesAlg) { encrypted = EncryptDecypt.EncryptStringToBytes_Aes(txt_pass.Text, aesAlg.Key, aesAlg.IV); } // encrypted text - password for (i = 0; i < encrypted.Length - 1; i++) { strEncrypted += encrypted[i].ToString() + ","; } strEncrypted += encrypted[i].ToString(); data[1] = strEncrypted; EncryptDecypt.writeXml(data, false); Session["username"] = data[0]; Session["staff"] = false; Response.Redirect("~/stockPage.aspx"); }
/// <summary> /// Event handler to add staff members to the staff.xml file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_add_Click(object sender, EventArgs e) { int i; string[] data = new string[4]; byte[] encrypted; string strEncrypted = ""; string key = ""; string iv = ""; data[0] = txt_username.Text; Aes aesAlg = Aes.Create(); // store key for de-cryption for (i = 0; i < aesAlg.Key.Length - 1; i++) { key += aesAlg.Key[i].ToString() + ","; } key += aesAlg.Key[i].ToString(); data[2] = key; // store iv for de-cryption for (i = 0; i < aesAlg.IV.Length - 1; i++) { iv += aesAlg.IV[i].ToString() + ","; } iv += aesAlg.IV[i].ToString(); data[3] = iv; using (aesAlg) { encrypted = EncryptDecypt.EncryptStringToBytes_Aes(txt_pass.Text, aesAlg.Key, aesAlg.IV); } //encrypted text - password for (i = 0; i < encrypted.Length - 1; i++) { strEncrypted += encrypted[i].ToString() + ","; } strEncrypted += encrypted[i].ToString(); data[1] = strEncrypted; EncryptDecypt.writeXml(data, true); }