protected void btnSignUp_Click(object sender, EventArgs e) { //Validate ValidateUserRegistration(); string APIKey = CreateRandom1(); string MerchantAccountID = CreateRandom2(); string MerchantFirstName = txtFirstName.Text; string MerchantLastName = txtLastName.Text; string MerchantCompanyName = txtCompanyName.Text; string MerchantEmail = txtEmail.Text; string MerchantPassword = txtPassword.Text; lblLabel.Text = "Your key is : " + APIKey; //int userTypeId = Convert.ToInt32(ddlUserTypeID.SelectedValue); if (UserRegistrationError.Count == 0) { //Check if email already exist String UserEmail = txtEmail.Text; Boolean flag = CheckIfEmailExist(UserEmail); if (flag == true) { Response.Write("Email already exists"); } else { //Register Merchant newMerchant = new Merchant { FirstName = MerchantFirstName, LastName = MerchantLastName, CompanyName = MerchantCompanyName, Email = MerchantEmail, Password = MerchantPassword, APIKey = APIKey, MerchantAccountID = MerchantAccountID }; //var Result = newMerchant.AddNewMerchant(); var ResponseReceived = newMerchant.AddNewMerchant(); if (ResponseReceived == true) { //User Registered //Save UserEmail in Session Called UserEmail Session.Add("userEmail", txtEmail.Text.ToString()); RegisterMerchantDetails.Visible = false; BankAccount.Visible = true; } else { Response.Write("Error Occured on the DATABASE"); } } } else { for (int i = 0; i < UserRegistrationError.Count; i++) { Response.Write(UserRegistrationError[i] + "<br/>"); } } String plainTextEmail = txtEmail.Text; String plainTextPassword = txtPassword.Text; String plainTextAPIKey = APIKey; String plainTextMerchantID = MerchantAccountID; String encryptedEmail; String encryptedPassword; String encryptedAPIKey; String encryptedMerchantAccountID; System.Text.UTF8Encoding encoder = new UTF8Encoding(); Byte[] EmailBytes; Byte[] PasswordBytes; Byte[] APIKeyBytes; Byte[] MerchantAccountIDBytes; EmailBytes = encoder.GetBytes(plainTextEmail); PasswordBytes = encoder.GetBytes(plainTextPassword); APIKeyBytes = encoder.GetBytes(plainTextAPIKey); MerchantAccountIDBytes = encoder.GetBytes(plainTextMerchantID); RijndaelManaged rmEncryption = new RijndaelManaged(); MemoryStream memStream = new MemoryStream(); CryptoStream encryptionStream = new CryptoStream(memStream, rmEncryption.CreateEncryptor(key, vector), CryptoStreamMode.Write); //Email encryptionStream.Write(EmailBytes, 0, EmailBytes.Length); encryptionStream.FlushFinalBlock(); memStream.Position = 0; Byte[] encryptedEmailBytes = new byte[memStream.Length]; memStream.Read(encryptedEmailBytes, 0, encryptedEmailBytes.Length); encryptionStream.Close(); memStream.Close(); //password memStream = new MemoryStream(); encryptionStream = new CryptoStream(memStream, rmEncryption.CreateEncryptor(key, vector), CryptoStreamMode.Write); encryptionStream.Write(PasswordBytes, 0, PasswordBytes.Length); encryptionStream.FlushFinalBlock(); memStream.Position = 0; Byte[] encryptedPasswordBytes = new byte[memStream.Length]; memStream.Read(encryptedPasswordBytes, 0, encryptedPasswordBytes.Length); encryptionStream.Close(); memStream.Close(); //APIKey memStream = new MemoryStream(); encryptionStream = new CryptoStream(memStream, rmEncryption.CreateEncryptor(key, vector), CryptoStreamMode.Write); encryptionStream.Write(APIKeyBytes, 0, APIKeyBytes.Length); encryptionStream.FlushFinalBlock(); memStream.Position = 0; Byte[] encryptedAPIKeyBytes = new byte[memStream.Length]; memStream.Read(encryptedAPIKeyBytes, 0, encryptedAPIKeyBytes.Length); encryptionStream.Close(); memStream.Close(); //MerchantAccountID memStream = new MemoryStream(); encryptionStream = new CryptoStream(memStream, rmEncryption.CreateEncryptor(key, vector), CryptoStreamMode.Write); encryptionStream.Write(MerchantAccountIDBytes, 0, MerchantAccountIDBytes.Length); encryptionStream.FlushFinalBlock(); memStream.Position = 0; Byte[] encryptedMerchantAccountIDBytes = new byte[memStream.Length]; memStream.Read(encryptedMerchantAccountIDBytes, 0, encryptedMerchantAccountIDBytes.Length); encryptionStream.Close(); memStream.Close(); encryptedEmail = Convert.ToBase64String(encryptedEmailBytes); encryptedPassword = Convert.ToBase64String(encryptedPasswordBytes); encryptedAPIKey = Convert.ToBase64String(encryptedAPIKeyBytes); encryptedMerchantAccountID = Convert.ToBase64String(encryptedMerchantAccountIDBytes); HttpCookie myCookie = new HttpCookie("LoginCookie"); myCookie.Values["Email"] = encryptedEmail; myCookie.Expires = new DateTime(2020, 2, 1); myCookie.Values["Password"] = encryptedPassword; myCookie.Expires = new DateTime(2020, 2, 1); myCookie.Values["APIKey"] = encryptedAPIKey; myCookie.Expires = new DateTime(2020, 2, 1); myCookie.Values["MerchantAccountID"] = encryptedMerchantAccountID; myCookie.Expires = new DateTime(2020, 2, 1); Response.Cookies.Add(myCookie); }