Showing me how to encrypt or decrypt file using AES. My issue here is I would like to check if the file is encrypted, don't encrypt it again and if the file is decrypted, don't decrypt it again.
I tried to use try and catch, two problems with this method:
It doesn't work with encrypt method cause it doesn't throw error when it comes to encryption
The decryption has to run till the end before throwing error which is a waste of resources
Showing me how to encrypt or decrypt file using AES. My issue here is I would like to check if the file is encrypted, don't encrypt it again and if the file is decrypted, don't decrypt it again.
The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and directories.
Thanks for your reply. I tested and the file attribute just came back as Archive not encrypted although the file can't be opened until it's descrypted.
You could perhaps check for this and if it doesn't match assume it is encrypted. Only your server side code will handle those encrypted files? Another option could be to use some naming convention.
Not sure for a "raw" algorithm but encryption tools such as PGP are likely adding their own header to the encrypted content.
Thank you for the reply. It seems a lot of work need to be done just to check this. I will keep looking. On another related topic Patrice. I wonder why if the file is encrypted and I encrypted it again. Now when I decrypted twice, I still can't open the
file. Do you happen to know why?
Thank you for the reply. It seems a lot of work need to be done just to check this. I will keep looking. On another related topic Patrice. I wonder why if the file is encrypted and I encrypted it again. Now when I decrypted twice, I still can't open the file.
Do you happen to know why?
According to your description, I have run a test demo on my side with encrypted twice and decrypted twice using the same key, it works on my side.
I used the sample you posted in the thread.
Could you please post more details information about your codes and pdf file?
Best Regards,
Brando
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
424 Points
1806 Posts
Is there a way I can check if the file has been encrypted
Jan 26, 2018 01:07 AM|asplearning|LINK
Hello everyone, I have a question. I found this site very helpful
https://www.aspsnippets.com/Articles/Encrypt-and-Decrypt-Word-Excel-PDF-Text-or-Image-Files-using-C-and-VBNet-in-ASPNet.aspx
Showing me how to encrypt or decrypt file using AES. My issue here is I would like to check if the file is encrypted, don't encrypt it again and if the file is decrypted, don't decrypt it again.
I tried to use try and catch, two problems with this method:
Is there a simple method to do this?
Thanks
All-Star
29513 Points
6025 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 26, 2018 02:05 AM|budugu|LINK
Check FileAttributes Enumeration, specifically attribute Encrypted
The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and directories.
"Don't be afraid to be wrong; otherwise you'll never be right."
Member
424 Points
1806 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 26, 2018 03:29 AM|asplearning|LINK
Thanks for your reply. I tested and the file attribute just came back as Archive not encrypted although the file can't be opened until it's descrypted.
All-Star
29513 Points
6025 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 26, 2018 04:58 PM|budugu|LINK
yes, it looks like that attribute set only when file system/OS encrypts the file.
"Don't be afraid to be wrong; otherwise you'll never be right."
Member
424 Points
1806 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 28, 2018 10:10 AM|asplearning|LINK
Anybody please? Thanks
All-Star
45870 Points
16703 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 28, 2018 10:39 AM|PatriceSc|LINK
Hi,
For a given type a file often starts with a given https://en.wikipedia.org/wiki/List_of_file_signatures
You could perhaps check for this and if it doesn't match assume it is encrypted. Only your server side code will handle those encrypted files? Another option could be to use some naming convention.
Not sure for a "raw" algorithm but encryption tools such as PGP are likely adding their own header to the encrypted content.
Member
424 Points
1806 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 29, 2018 03:32 AM|asplearning|LINK
Thank you for the reply. It seems a lot of work need to be done just to check this. I will keep looking. On another related topic Patrice. I wonder why if the file is encrypted and I encrypted it again. Now when I decrypted twice, I still can't open the file. Do you happen to know why?
Star
9591 Points
3012 Posts
Re: Is there a way I can check if the file has been encrypted
Jan 30, 2018 08:31 AM|Brando ZWZ|LINK
Hi asplearning,
According to your description, I have run a test demo on my side with encrypted twice and decrypted twice using the same key, it works on my side.
I used the sample you posted in the thread.
Could you please post more details information about your codes and pdf file?
Best Regards,
Brando
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.