Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to encrypt a zip file using PGP Encryption?

I am able to encrypt a text file as per the below code. But unable to encrypt a zip file though.
C#
private void encryptnew()
       {
           FileInfo fi = new FileInfo(path1);


           //GetFile();

           string path = ConfigurationSettings.AppSettings["NEW_FILE"].ToString();
           // Delete the file if it exists.
           if (File.Exists(path))
           {
               File.Delete(path);
           }

           //Create the file.
           using (FileStream fs = fi.Create())
           {
               Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
               // Add some information to the file.
               fs.Write(info, 0, info.Length);
               fs.Flush();
               fs.Close();

               FileStream str = new FileStream(path, FileMode.Create);
               PgpEncryptionKeys objPgpEncryptionKeys = new PgpEncryptionKeys(PublicKey, PrivateKey, password, true);
               PgpEncrypt objPgpEncrypt = new PgpEncrypt(objPgpEncryptionKeys);
               objPgpEncrypt.EncryptAndSign(str, fi);
               str.Flush();
               str.Close();
           }
       }
Posted
Updated 23-Mar-15 23:27pm
v2
Comments
Richard MacCutchan 24-Mar-15 4:46am    
A zip file is already binary (as are text files in reality), so you do not need to try getting the content in a texct encoding. Just read the raw data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900