Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

C# how to decrypt an encrypted excel file before displaying it to a datagridview?

$
0
0

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Data.OleDb; using System.Security.Cryptography; namespace EnDecrytion_tryout { publicpartialclassReadExcel : Form { privatestaticstring key = "asdfghjklzxcasdfghjklzxcasdfghjk"; privatestaticstring IV = "qwertyuiopasdfgh"; public ReadExcel() { InitializeComponent(); browse.Click += newEventHandler(browse_Click); btnloadexcel.Click += newEventHandler(btnloadexcel_Click); } void btnloadexcel_Click(object sender, EventArgs e) { string pathcon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" +

label1.Text + @";Extended Properties =""Excel 8.0;IMEX=1

HDR=Yes;ImportMixedTypes=Text;TypeGuessRows=0"""; OleDbConnection conn = newOleDbConnection(pathcon); var adapter = newOleDbDataAdapter("SELECT CATEGORY,

ITEM_NAME, SUBNAME_or_BRAND, ITEM_SIZE, ITEM_QUANTITY_DESCRIPTION, ITEM_UNIT, QUANTITY, REFERENCE, TRANSACTION, TRANSACTION_DATE" +")"+ "FROM [SHEET1$]", conn); var ds = newDataSet(); adapter.Fill(ds); DataTable QueryTable = ds.Tables[0]; dataGridView1.DataSource = QueryTable; } void browse_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { label1.Text = openFileDialog1.FileName; } } publicstaticstring decrypt(string adap) { byte[] encryptedbytes = Convert.FromBase64String(adap); AesCryptoServiceProvider aes = newAesCryptoServiceProvider(); aes.BlockSize = 128; aes.KeySize = 256; aes.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(key); aes.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV); aes.Padding = PaddingMode.PKCS7; aes.Mode = CipherMode.CBC; ICryptoTransform crypto = aes.CreateDecryptor(aes.Key, aes.IV); byte[] secret = crypto.TransformFinalBlock(encryptedbytes, 0,

encryptedbytes.Length); crypto.Dispose(); return System.Text.ASCIIEncoding.ASCII.GetString(secret); } } }

- this is my code for connection and decryption but i don't know where i will implement the decryption code to decrypt the excel file before displaying it to datagridview.

(by the way i also used AES for encrypting every cell entry in the excel table)

-- I appreciate some help. thanks



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>