VeryPDF Encrypt PDF provides three versions to meet different needs of different users: Encrypt PDF (GUI) for non-commercial users, Encrypt PDF Command Line and Encrypt PDF COM for developers and server operators. Want to. PDF Encrypt Features. Supports Adobe Standard 40-bit Encryption and Adobe Advanced 128-bit Encryption. Supports AES encryption. Password protect opening of the document. Supports user password and owner password. Prevent. Encrypt PDF Command Line Options, protect your PDF files from command line. Encrypt and Decrypt Word, Excel, PDF, Text or Image Files using C# and VB. Net in ASP. Net. In this article I will explain how to encrypt and decrypt file such as Word (DOC, DOCX), Excel (XLS, XLSX), PDF, Text (TXT) documents or JPG, PNG or GIF Images using C# and VB. Net in ASP. Net website. How To Encrypt Pdf FilesThe file will be uploaded for Encryption and Decryption of Files. For Encryption and Decryption of files, the AES Symmetric key (Same key) algorithm is used. The encrypted and decrypted files can be saved inside folders on disk or can be downloaded to client user. HTML Markup. The HTML markup consists of File. Upload control and two Buttons.< asp: File. Upload. ID="File. Upload. 1"runat="server"/> < hr/> < asp: Button. ID="btn. Encrypt"Text="Encrypt File"runat="server"On. Click="Encrypt. File"/> < asp: Button. ID="btn. Decrypt"Text="Decrypt File"runat="server"On. Click="Decrypt. File"/> Namespaces. You will need to import the following namespaces. C#using System. IO; using System. Security. Cryptography; VB. Net. Imports System. IOImports System. Security. Cryptography. AES Algorithm Encryption and Decryption functions. Below are the functions for Encryption and Decryption which will be used for the Encrypting or Decrypting Files. File Encryption. The following Button click event handler encrypts the uploaded file. Name, Content Type and the File Bytes of the uploaded file are fetched and the file is save on folder on disk. Once the file is saved in the same location its encrypted counterpart is saved with the postfix “_enc”. How To Encrypt Pdf File MacThe encrypted file is then sent for download by the client user. After download both the files are deleted. C#protectedvoid Encrypt. File(object sender, Event. Args e){ //Get the Input File Name and Extension. string file. Name = Path. Get. MEO File Encryption Software Encrypt and decrypt files and keep your data secure. MEO is easy file encryption software for Mac or Windows that will encrypt or decrypt files of any type. Protect sensitive data against. PDF Encrypt & Decrypt. Protect your PDF files with passwords and prevent PDF files from being printed, changed, copied, extracted, signed, filled, assembled and/or merged. Buy Now Download. File. Name. Without. Extension(File. Upload. Posted. File. File. Name); string file. Extension = Path. Get. Extension(File. Upload. 1. Posted. File. File. Name); //Build the File Path for the original (input) and the encrypted (output) file. string input = Server. Map. Path("~/Files/") + file. Name + file. Extension; string output = Server. Map. Path("~/Files/") + file. Name + "_enc" + file. Extension; //Save the Input File, Encrypt it and save the encrypted file in output path. File. Upload. 1. Save. As(input); this. Encrypt(input, output); //Download the Encrypted File. Response. Content. Type = File. Upload. 1. Posted. File. Content. Type; Response. Clear(); Response. Append. Header("Content- Disposition", "attachment; filename=" + Path. Get. File. Name(output)); Response. Write. File(output); Response. Flush(); //Delete the original (input) and the encrypted (output) file. File. Delete(input); File. Delete(output); Response. End(); }privatevoid Encrypt(string input. File. Path, string outputfile. Path){ string Encryption. Key = "MAKV2. SPBNI9. Aes encryptor = Aes. Create()) { Rfc. Derive. Bytes pdb = new. Rfc. 28. 98. Derive. Bytes(Encryption. Key, newbyte[] { 0x. Key = pdb. Get. Bytes(3. IV = pdb. Get. Bytes(1. File. Stream fs. Output = new. File. Stream(outputfile. Path, File. Mode. Create)) { using (Crypto. Stream cs = new. Crypto. Stream(fs. Output, encryptor. Create. Encryptor(), Crypto. Stream. Mode. Write)) { using (File. Stream fs. Input = new. File. Stream(input. File. Path, File. Mode. Open)) { int data; while ((data = fs. Input. Read. Byte()) != - 1) { cs. Write. Byte((byte)data); } } } } }}VB. Net. Protected. Sub Encrypt. File(sender As. Object, e As. Event. Args) 'Get the Input File Name and Extension. Dim file. Name As. String = Path. Get. File. Name. Without. Extension(File. Upload. Posted. File. File. Name) Dim file. Extension As. String = Path. Get. Extension(File. Upload. 1. Posted. File. File. Name) 'Build the File Path for the original (input) and the encrypted (output) file. Dim input As. String = Convert. To. String(Server. Map. Path("~/Files/") & file. Name) & file. Extension Dim output As. String = Convert. To. String((Server. Map. Path("~/Files/") & file. Name) + "_enc") & file. Extension 'Save the Input File, Encrypt it and save the encrypted file in output path. File. Upload. 1. Save. As(input) Me. Encrypt(input, output) 'Download the Encrypted File. Response. Content. Type = File. Upload. 1. Posted. File. Content. Type Response. Clear() Response. Append. Header("Content- Disposition", "attachment; filename=" + Path. Get. File. Name(output)) Response. Write. File(output) Response. Flush() 'Delete the original (input) and the encrypted (output) file. File. Delete(input) File. Delete(output) Response. End()End. Sub. Protected. Sub Decrypt. File(sender As. Object, e As. Event. Args) 'Get the Input File Name and Extension Dim file. Name As. String = Path. Get. File. Name. Without. Extension(File. Upload. Posted. File. File. Name) Dim file. Extension As. String = Path. Get. Extension(File. Upload. 1. Posted. File. File. Name) 'Build the File Path for the original (input) and the decrypted (output) file Dim input As. String = Convert. To. String(Server. Map. Path("~/Files/") & file. Name) & file. Extension Dim output As. String = Convert. To. String((Server. Map. Path("~/Files/") & file. Name) + "_dec") & file. Extension 'Save the Input File, Decrypt it and save the decrypted file in output path. File. Upload. 1. Save. As(input) Me. Decrypt(input, output) 'Download the Decrypted File. Response. Clear() Response. Content. Type = File. Upload. 1. Posted. File. Content. Type Response. Append. Header("Content- Disposition", "attachment; filename=" + Path. Get. File. Name(output)) Response. Write. File(output) Response. Flush() 'Delete the original (input) and the decrypted (output) file. File. Delete(input) File. Delete(output) Response. End()End. Sub. Private. Shared. Function Assign(Of T)(By. Ref source As T, By. Val value As T) As T source = value Return value. End. Function. For VB. Net I have made use of a utility method named Assign for assigning variable values and also returning the same. In C# it can be done easily but to do same in VB. Net we need a utility method. File Decryption. Similar to Encryption process, the following Button click event handler encrypts the uploaded file. Name, Content Type and the File Bytes of the uploaded file are fetched and the file is save on folder on disk. Once the file is saved in the same location its decrypted counterpart is saved with the postfix “_dec”. The decrypted file is then sent for download by the client user. After download both the files are deleted. C#protectedvoid Decrypt. File(object sender, Event. Args e){ //Get the Input File Name and Extension string file. Name = Path. Get. File. Name. Without. Extension(File. Upload. Posted. File. File. Name); string file. Extension = Path. Get. Extension(File. Upload. 1. Posted. File. File. Name); //Build the File Path for the original (input) and the decrypted (output) file string input = Server. Map. Path("~/Files/") + file. Name + file. Extension; string output = Server. Map. Path("~/Files/") + file. Name + "_dec" + file. Extension; //Save the Input File, Decrypt it and save the decrypted file in output path. File. Upload. 1. Save. As(input); this. Decrypt(input, output); //Download the Decrypted File. Response. Clear(); Response. Content. Type = File. Upload. 1. Posted. File. Content. Type; Response. Append. Header("Content- Disposition", "attachment; filename=" + Path. Get. File. Name(output)); Response. Write. File(output); Response. Flush(); //Delete the original (input) and the decrypted (output) file. File. Delete(input); File. Delete(output); Response. End(); }privatevoid Decrypt(string input. File. Path, string outputfile. Path){ string Encryption. Key = "MAKV2. SPBNI9. Aes encryptor = Aes. Create()) { Rfc. Derive. Bytes pdb = new. Rfc. 28. 98. Derive. Bytes(Encryption. Key, newbyte[] { 0x. Key = pdb. Get. Bytes(3. IV = pdb. Get. Bytes(1. File. Stream fs. Input = new. File. Stream(input. File. Path, File. Mode. Open)) { using (Crypto. Stream cs = new. Crypto. Stream(fs. Input, encryptor. Create. Decryptor(), Crypto. Stream. Mode. Read)) { using (File. Stream fs. Output = new. File. Stream(outputfile. Path, File. Mode. Create)) { int data; while ((data = cs. Read. Byte()) != - 1) { fs. Output. Write. Byte((byte)data); } } } } }}VB. Net. Private. Sub Encrypt(input. File. Path As. String, outputfile. Path As. String) Dim Encryption. Key As. String = "MAKV2. SPBNI9. 92. 12" Using encryptor As. Aes = Aes. Create() Dim pdb As. New. Rfc. 28. 98. Derive. Bytes(Encryption. Key, New. Byte() {& H4. H7. 6, & H6. 1, & H6. E, & H2. 0, & H4. D, _ & H6. H6. 4, & H7. 6, & H6. H6. 4, & H6. 5, _ & H7. Key = pdb. Get. Bytes(3. IV = pdb. Get. Bytes(1. Using fs As. New. File. Stream(outputfile. Path, File. Mode. Create) Using cs As. New. Crypto. Stream(fs, encryptor. Create. Encryptor(), Crypto. Stream. Mode. Write) Using fs. Input As. New. File. Stream(input. File. Path, File. Mode. Open) Dim data As. Integer While (Assign(data, fs. Input. Read. Byte())) < > - 1 cs. Write. Byte(CByte(data)) End. While End. Using End. Using End. Using End. Using. End. Sub. Private. Sub Decrypt(input. File. Path As. String, outputfile. Path As. String) Dim Encryption. Key As. String = "MAKV2. SPBNI9. 92. 12" Using encryptor As. Aes = Aes. Create() Dim pdb As. New. Rfc. 28. 98. Derive. Bytes(Encryption.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2016
Categories |