在php中如何在特定文件夹中找到已经加密的文件
我正在使用 PGP(GNU Privacy Guard)来加密文件。 加密时我删除了加密文件的“.pgp”扩展名。
现在我想知道特定文件夹中哪个文件已经加密。
注意:- 我的目标是......不要对任何文件加密两次......所以在加密任何文件之前......我想检查文件是否已经加密。
在php中我们能找出哪个文件已经加密了吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PGP 文件全部以
"-----BEGIN PGP MESSAGE-----"
开头。所以你可以这样做:
PGP file all starts with
"-----BEGIN PGP MESSAGE-----"
.So you can do something like this:
我真的不太了解它是如何工作的,或者如何查看文件的内容来判断它是否已正确加密,但是您可以尝试解密它们吗?如果您知道您只处理纯文本文件,您可以检查解密数据的前 500 个字节,如果有奇怪的字符(在标准 az AZ 0-9 + 标点符号之外),那么这可能是一个线索文件未加密。
我知道,这确实是一个半途而废的答案,但它有点长,不适合评论。
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.
除非您了解加密中使用的算法,否则您不能。一旦理解了它,您就可以应用它来检查文件是否已经加密。
还要检查以确保 PGP 中已有一个功能可用于检查某些内容是否已加密。这通常出现在加密解决方案中。
谢谢
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
OpenPGP 数据有两种可能的格式:二进制格式和 ascii 装甲格式。
Ascii 装甲文件很容易通过查找“-----BEGIN PGP MESSAGE-----”来识别,也可以使用 unix 命令
file
来完成:@ZZ_Coders 答案完全没问题如果您只处理 ascii 装甲加密文件。
如果它显示其他内容,则它不是 OpenPGP 消息 - 或二进制格式。这不太容易识别(至少我不知道您可以查找哪些魔术包),但您可以轻松地使用
gpg
命令来测试该文件:如果不是加密后,响应将如下所示:
在 PHP 中,您可以使用以下代码来检查文件是否经过 OpenPGP 加密:
There are two possible formats for OpenPGP data, binary and ascii armored.
Ascii-armored files are easy to recognize by looking for "-----BEGIN PGP MESSAGE-----" which can also be done using the unix command
file
:@ZZ_Coders answer is totally fine if you're only dealing with ascii armored encrypted files.
If it shows something else, it's not an OpenPGP message - or in binary format. This isn't as easy to recognize (at least I don't know which magic packets you could look for), but you can easily use the
gpg
command to test the file:If it isn't encrypted, response will look like this:
In PHP, you could use this code to check if a file is OpenPGP-encrypted: