Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I have a CryptoStream that takes a file and then encrypts said file and outputs a new file with the extension .enc how do i add a icon to this new encrypted file within the CryptoStream method?

This is my CryptoStream method:

C#
using (FileStream inputFileStream = File.Open(inputFile, FileMode.Open))
                   using (FileStream outputFileStream = File.Open(encryptedFile, FileMode.Create))
                   {
                       using (AesCryptoServiceProvider aesCryptoServiceProvider = new AesCryptoServiceProvider())
                       {

                           aesCryptoServiceProvider.BlockSize = 128;
                           aesCryptoServiceProvider.KeySize = 256;
                           aesCryptoServiceProvider.Key = keyBytes;
                           aesCryptoServiceProvider.IV = ivBytes;

                           ICryptoTransform cryptoTransform = aesCryptoServiceProvider.CreateEncryptor();

                           using (CryptoStream cryptoStream = new CryptoStream(outputFileStream, cryptoTransform, CryptoStreamMode.Write))
                           {
                               byte[] buffer = new byte[inputFileStream.Length];
                               inputFileStream.Read(buffer, 0, buffer.Length);
                               cryptoStream.Write(buffer, 0, buffer.Length);
                               MessageBox.Show("The File Was Successfully Encrypted", "Encrypted!", MessageBoxButton.OK, MessageBoxImage.Information);
                           }
                       }
                   }


The path to the icon is set by the user and is displayed in a textbox called OpenIcon.text!

It may not be possible adding a icon to the file in the CryptoStream so if anyone has any other ideas on how one would add an icon to the encrypted file after the CryptoStream?
Posted

1 solution

First of all, you can not assign an icon to a stream so save the file first. Then probably, IconHandlers can do your job but it's not that easy.
You need to create a shell extension handler to do this and preferably you do this using language like C++.

Check this complete article in MSDN
https://msdn.microsoft.com/en-us/library/windows/desktop/cc144122(v=vs.85).aspx[^]

Hope, it helps :)
 
Share this answer
 
Comments
Yusuf_20_x 27-Jun-15 18:57pm    
Thank you Suvendu Shekhar Giri i did see that article but i could only find examples in c++

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