ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Read text from MS Word and Save/Retrive in Encrypt Decrypt format using C# in ASp.Net<p>Hi&nbsp;<a class="username" rel="Firuz">Firuz,</a></p> <p>I will get back to you on tomorrow.</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/Thu, 15 Sep 2016 11:09:31 GMTRead text from MS Word and Save/Retrive in Encrypt Decrypt format using C# in ASp.Net<p>Hi <a class="username" rel="Firuz"> Firuz</a>,</p> <p>Refer the below article. While fetching the record from database decrypt the data and assign to the control you want to display.</p> <h1 class="header"><a title="AES Encryption Decryption (Cryptography) Tutorial with example in ASP.Net using C# and VB.Net'a" href="http://www.aspsnippets.com/Articles/AES-Encryption-Decryption-Cryptography-Tutorial-with-example-in-ASPNet-using-C-and-VBNet.aspx">AES Encryption Decryption (Cryptography) Tutorial with example in ASP.Net using C# and VB.Net</a></h1>https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/Fri, 16 Sep 2016 03:21:27 GMTRead text from MS Word and Save/Retrive in Encrypt Decrypt format using C# in ASp.Net<p>I used this article. But I can't use encrypt for top code.</p>https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/Fri, 16 Sep 2016 03:56:49 GMTRead text from MS Word and Save/Retrive in Encrypt Decrypt format using C# in ASp.Net<p>Hi <a class="username" rel="Firuz"> Firuz</a>,</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;div&gt; &lt;asp:Button ID=&#34;btnImport&#34; runat=&#34;server&#34; Text=&#34;Import&#34; OnClick=&#34;Import&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:GridView ID=&#34;gvQuestions&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;true&#34; OnRowDataBound=&#34;gvQuestions_RowDataBound&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">protected void Import(object sender, EventArgs e) { SqlConnection con = new SqlConnection(constr); Application word = new Application(); Document doc = new Document(); string filePath = Server.MapPath(&#34;~/Files/Test.docx&#34;); object missing = System.Type.Missing; object fileName = filePath; doc = word.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); String read = string.Empty; List&lt;string&gt; data = new List&lt;string&gt;(); for (int i = 0; i &lt; doc.Paragraphs.Count; i++) { string temp = doc.Paragraphs[i + 1].Range.Text.Trim(); if (temp != string.Empty) data.Add(temp); } doc.Close(ref missing, ref missing, ref missing); System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn(&#34;Id&#34;,typeof(int)), new System.Data.DataColumn(&#34;Question&#34;), new System.Data.DataColumn(&#34;Answer1&#34;), new System.Data.DataColumn(&#34;Answer2&#34;), new System.Data.DataColumn(&#34;Answer3&#34;), new System.Data.DataColumn(&#34;Answer4&#34;), new System.Data.DataColumn(&#34;CorrectAnswer&#34;) }); int totalQuestionCount = 0; int rowNo = 1; System.Data.DataRow dr = dt.NewRow(); for (int i = 0; i &lt; data.Count; i++) { string type = string.Empty; if (data[i].Contains(&#34;$&#34;) || data[i].Contains(&#34;&copy;&#34;)) { type = &#34;option&#34;; if (i != 0) { if ((!data[i - 1].Contains(&#34;@&#34;))) { type = &#34;new line option&#34;; } } } else { type = &#34;question&#34;; } int optionCount = 2; switch (type) { case &#34;question&#34;: dr[0] = rowNo; dr[1] = data[i].Replace(&#34;@&#34;, &#34;&#34;).Trim(); rowNo++; break; case &#34;option&#34;: foreach (string option in data[i].Split(&#39;;&#39;)) { if (!string.IsNullOrEmpty(option)) { if (option.Contains(&#34;$&#34;)) { dr[optionCount] = option.Replace(&#34;$&#34;, &#34;&#34;).Trim(); } else if (option.Contains(&#34;&copy;&#34;)) { //* Option*// dr[optionCount] = option.Replace(&#34;&copy;&#34;, &#34;&#34;).Trim(); dr[6] = option.Split(&#39;)&#39;)[1].Trim(); } optionCount++; } } break; case &#34;new line option&#34;: foreach (string option in data[i].Split(&#39;;&#39;)) { if (!string.IsNullOrEmpty(option)) { int colIndex = 0; if (option.Contains(&#34;$A&#34;) || option.Contains(&#34;&copy;A&#34;)) { colIndex = 2; } if (option.Contains(&#34;$B&#34;) || option.Contains(&#34;&copy;B&#34;)) { colIndex = 3; } if (option.Contains(&#34;$C&#34;) || option.Contains(&#34;&copy;C&#34;)) { colIndex = 4; } if (option.Contains(&#34;$D&#34;) || option.Contains(&#34;&copy;D&#34;)) { colIndex = 5; } dt.Rows[dt.Rows.Count - 1][colIndex] = option.Replace(&#34;$&#34;, &#34;&#34;).Trim(); if (option.Contains(&#34;&copy;&#34;)) { dt.Rows[dt.Rows.Count - 1][colIndex] = option.Replace(&#34;&copy;&#34;, &#34;&#34;).Trim(); dt.Rows[dt.Rows.Count - 1][6] = option.Split(&#39;)&#39;)[1].Trim(); } } } break; } if (i != 0 &amp;&amp; data[i - 1].Contains(&#34;@&#34;)) { dt.Rows.Add(dr); totalQuestionCount++; dr = dt.NewRow(); } } ((_Application)word).Quit(); foreach (DataRow row in dt.Rows) { SqlCommand cmd = new SqlCommand(&#34;INSERT INTO Encrypt VALUES(@Id,@Question,@Answer1,@Answer2,@Answer3,@Answer4,@CorrectAnswer)&#34;, con); cmd.Parameters.AddWithValue(&#34;@Id&#34;, row[&#34;Id&#34;]); cmd.Parameters.AddWithValue(&#34;@Question&#34;, Encrypt(row[&#34;Question&#34;].ToString())); cmd.Parameters.AddWithValue(&#34;@Answer1&#34;, Encrypt(row[&#34;Answer1&#34;].ToString())); cmd.Parameters.AddWithValue(&#34;@Answer2&#34;, Encrypt(row[&#34;Answer2&#34;].ToString())); cmd.Parameters.AddWithValue(&#34;@Answer3&#34;, Encrypt(row[&#34;Answer3&#34;].ToString())); cmd.Parameters.AddWithValue(&#34;@Answer4&#34;, Encrypt(row[&#34;Answer4&#34;].ToString())); cmd.Parameters.AddWithValue(&#34;@CorrectAnswer&#34;, Encrypt(row[&#34;CorrectAnswer&#34;].ToString())); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } GetResult(); } private string Encrypt(string clearText) { string EncryptionKey = &#34;MAKV2SPBNI99212&#34;; byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); encryptor.Key = pdb.GetBytes(32); encryptor.IV = pdb.GetBytes(16); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(clearBytes, 0, clearBytes.Length); cs.Close(); } clearText = Convert.ToBase64String(ms.ToArray()); } } return clearText; } private string Decrypt(string cipherText) { string EncryptionKey = &#34;MAKV2SPBNI99212&#34;; byte[] cipherBytes = Convert.FromBase64String(cipherText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); encryptor.Key = pdb.GetBytes(32); encryptor.IV = pdb.GetBytes(16); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(cipherBytes, 0, cipherBytes.Length); cs.Close(); } cipherText = Encoding.Unicode.GetString(ms.ToArray()); } } return cipherText; } private void GetResult() { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;SELECT * FROM Encrypt&#34;, con); DataSet getdt = new DataSet(); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(getdt); gvQuestions.DataSource = getdt; gvQuestions.DataBind(); } protected void gvQuestions_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[1].Text = Decrypt(e.Row.Cells[1].Text); e.Row.Cells[2].Text = Decrypt(e.Row.Cells[2].Text); e.Row.Cells[3].Text = Decrypt(e.Row.Cells[3].Text); e.Row.Cells[4].Text = Decrypt(e.Row.Cells[4].Text); e.Row.Cells[5].Text = Decrypt(e.Row.Cells[5].Text); e.Row.Cells[6].Text = Decrypt(e.Row.Cells[6].Text); } } </pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><img src="https://i.imgur.com/yyALFgW.gif" alt="" width="468" height="287" /></p> <p>I hope works for you.</p>https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/https://www.aspforums.net:443/Threads/377377/Read-text-from-MS-Word-and-SaveRetrive-in-Encrypt-Decrypt-format-using-C-in-ASpNet/Fri, 16 Sep 2016 04:28:43 GMT