public void SetCookie(string CookieName, string CookieValue) { HttpContext.Current.Response.Cookies.Set(HttpContext.Current.Request.Cookies[CookieName] ?? new HttpCookie(CookieName, "")); //HttpContext.Current.Response.Cookies[CookieName].Value = rijndaelKey.Encrypt(CookieValue); //if (!_SSODomain.Equals("")) //{ // System.Web.HttpContext.Current.Response.Cookies[CookieName].Path = "/"; // System.Web.HttpContext.Current.Response.Cookies[CookieName].Domain = _SSODomain; //} //System.Web.HttpContext.Current.Response.Cookies[CookieName].Expires = DateTime.Now.AddMinutes(_LifeTime); //System.Web.HttpContext.Current.Response.Cookies[CookieName].HttpOnly = true; FormsAuthentication.SetAuthCookie(rijndaelKey.Encrypt(CookieValue), false); }
public static string Encrypt(string stringToEncrypt) { string pp = MachineKeySettings.MachineKey; GBRandomNumberGenerator.Generator generator = new GBRandomNumberGenerator.Generator(16); _iv = generator.GeneratePassword(); RijndaelEnhanced crypto = new RijndaelEnhanced(pp, _iv); return crypto.Encrypt(stringToEncrypt); }
/// <summary> /// </summary> /// <param name="DocKeys"></param> /// <param name="ClearText">don't Rijndael encrypt</param> /// <returns>A jsoned & modified base64 string suitable for parameter UrlEncoding</returns> public static string DocIdFromKeys(Dictionary <string, string> DocKeys, bool ClearText = false) { return ((ClearText ? Serialize.Json.Serialize(DocKeys) : rijndaelKey.Encrypt(Serialize.Json.Serialize(DocKeys))) .Replace("/", "_") .Replace("+", "-") .Replace("=", "%3d")); //TODO:compare Compression routines yielding the same string format used here in DocIdFromKeys }
private const string _initVector = "@1B2c3D4e5F6g7H8"; // must be 16 bytes public static string EncryptString(string str) { string cipherText; string passPhrase = _passPhrase; string initVector = _initVector; RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(passPhrase, initVector); cipherText = rijndaelKey.Encrypt(str); return(cipherText); }
public static string Encrypt(string key, string value) { string encryptedValue = string.Empty; try { RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(key); // string hashValue = HashEncryption.SHA256Hash(value); encryptedValue = rijndaelKey.Encrypt(value); } catch (Exception error) { Console.WriteLine("Error Occurred | Encrypter Failed |" + error); } return(encryptedValue); }
protected void btEcrypt_Click(object sender, EventArgs e) { RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(txtKey.Text, "@1B2c3D4e5F6g7H8"); txtResult.Text = rijndaelKey.Encrypt(txtData.Text); }
private void UpdateData() { try { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); List <Field> fields = jsSerializer.Deserialize <List <Field> >(Request.Form["fields"]); Campaign objcampaign = (Campaign)Session["Campaign"]; XmlDocument xDocCampaign = new XmlDocument(); xDocCampaign.LoadXml(Serialize.SerializeObject(objcampaign, "Campaign")); System.Text.StringBuilder sbQuery = new System.Text.StringBuilder(); System.Collections.ArrayList alfields = new ArrayList(); bool bolLastWasEncrypted = false; if (fields.Count > 0) { sbQuery.Append("UPDATE Campaign SET "); for (int i = 0; i < fields.Count; i++) { Field field = fields[i]; string fieldName = field.name; string fieldValue = field.value; if (i == (fields.Count - 1)) { // uniquekey sbQuery.AppendFormat("WHERE {0}={1} ", fieldName, fieldValue); break; } if (alfields.Contains(fieldName)) { continue; } alfields.Add(fieldName); //if it is encrypted then run the algorythm if (field.type == "encrypted") { if (fieldValue != "This is encrypted data") { string plainText = fieldValue; string cipherText = ""; // encrypted text string passPhrase = "whatevesfasdfasdfr23"; // can be any string string initVector = "Qt@&^SDF15F6g7H8"; // must be 16 bytes // Before encrypting data, we will append plain text to a random // salt value, which will be between 4 and 8 bytes long (implicitly // used defaults). RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(passPhrase, initVector); Console.WriteLine(String.Format("Plaintext : {0}\n", plainText)); // Encrypt the same plain text data 10 time (using the same key, // initialization vector, etc) and see the resulting cipher text; // encrypted values will be different. for (int ii = 0; ii < 10; ii++) { cipherText = rijndaelKey.Encrypt(plainText); Console.WriteLine( String.Format("Encrypted #{0}: {1}", ii, cipherText)); plainText = rijndaelKey.Decrypt(cipherText); } // Make sure we got decryption working correctly. Console.WriteLine(String.Format("\nDecrypted :{0}", plainText)); fieldValue = cipherText; fieldValue = "'" + fieldValue + "'"; } } else { fieldValue = fieldValue.Replace("'", "''"); if (fieldValue.Trim() != "") { if (field.type == "s" || field.type == "dt" || IsCampaignDefined(fieldName)) { fieldValue = "'" + fieldValue + "'"; } else if (field.type == "bool") { bool value = false; try { if (IsInt(fieldValue)) { value = Convert.ToBoolean(Convert.ToInt32(fieldValue)); } else { value = Convert.ToBoolean(fieldValue); } } catch { } fieldValue = value ? "1" : "0"; } } else { fieldValue = "null"; } } if (fieldValue != "This is encrypted data") { if (!bolLastWasEncrypted) { sbQuery.AppendFormat("{2}{0}={1} ", fieldName, fieldValue, i == 0 ? "" : ","); } else { sbQuery.AppendFormat("{0}={1} ", fieldName, fieldValue); } bolLastWasEncrypted = false; } else { //set that last field in recordset an encrypted so don't use comma bolLastWasEncrypted = true; } } string sbQuerystring = sbQuery.ToString(); if (!sbQuerystring.StartsWith("UPDATE Campaign SET WHERE")) { CampaignService campService = new CampaignService(); if (Session["LoggedAgent"] != null) { ActivityLogger.WriteAgentEntry((Agent)Session["LoggedAgent"], "Posting campaign update query: '{0}'.", sbQuery.ToString()); } campService.UpdateCampaignDetails(xDocCampaign, sbQuery.ToString()); long key = 0; try { key = Convert.ToInt64(Session["UniqueKey"]); } catch { } if (key > 0) { DataSet dsCampaigndtls = (DataSet)Session["CampaignDtls"]; long queryId = 0; try { queryId = Convert.ToInt64(dsCampaigndtls.Tables[0].Rows[0]["QueryId"]); } catch { } dsCampaigndtls = campService.GetCampaignDetailsByKey(objcampaign.CampaignDBConnString, key, queryId); if (dsCampaigndtls != null) { if (dsCampaigndtls.Tables[0].Rows.Count > 0) { Session["CampaignDtls"] = dsCampaigndtls; } } } } } } catch (Exception ex) { if (Session["LoggedAgent"] != null) { ActivityLogger.WriteAgentEntry((Agent)Session["LoggedAgent"], "PostCampaignDetails UpdateData exception : '{0}'.", ex.Message); } throw ex; } }
public string Encrypt(string data, string key) { var rij = new RijndaelEnhanced(key); return rij.Encrypt(data); }
public string Encrypt(string data, string key) { var rij = new RijndaelEnhanced(key); return(rij.Encrypt(data)); }