string text = string.Empty; using (StreamReader streamReader = new StreamReader(@"D:\\Website examples\myproject\Final\RandomQuestionBank.pdf", Encoding.UTF8)) { text = streamReader.ReadToEnd(); } txt_encrypt.Text = this.Encrypt(text); var path = Server.MapPath("~/Final"); var directinfo = new DirectoryInfo(path); if (directinfo.Exists) { var newfolder = directinfo.CreateSubdirectory("Encrypt Qbank"); string encryptpath = Server.MapPath("~/" + newfolder + "\\" + "encrypt file"); File.WriteAllText(encryptpath, txt_encrypt.Text); File.SetAttributes(encryptpath, FileAttributes.ReadOnly); } } private string Encrypt(string clearText) { string EncryptionKey = label_key.Text; 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()); } txt_encrypt.Text = clearText; } return clearText; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)