views:

41

answers:

3

Hi,

I am using PGP (GNU Privacy Guard) for encrypting the file. while encrypting i removed the '.pgp' extension of encrypted file.

Now some how i want to know which file is already encrypted in the specific folder.

Note :- my goal is that ... do not encrypt any file twice ... so before encrypt any file .. i want to check is the file already encrypted.

in php can we find out which file is already encrypted ?

Thanks & Regards Rahul.

A: 

I really don't know much about how it works, or how you could look at the contents of the file to tell if it is encrypted properly, but could you try decrypting them? If you know you're only working with plain text files, you could examine the first 500 bytes of the decrypted data and if there's strange characters (outside the standard a-z A-Z 0-9 + punctuation, etc), then that could be a clue that the file wasn't encrypted.

This really is a half-arsed answer, I know, but it was a bit long to fit into a comment.

nickf
Has the potential to be brutally slow.
meagar
A: 

You can't unless you understand the algorithm used in the encryption. Once you understand it, you can apply that to check whether a file is already encrypted.

Also check to make sure that there is already a function available in PGP for checking if something is already encrypted. This is usually present in encryption solutions.

Thanks

Sarfraz
+1  A: 

PGP file all starts with "-----BEGIN PGP MESSAGE-----". So you can do something like this,

  $content = file_get_contents($filename);
  $encrypted = strpos($content,'-----BEGIN PGP MESSAGE-----') == 0;
ZZ Coder