简体   繁体   English

用openssl解析加密的文件

[英]Parse encrypted file with openssl

I have encrypted a file with openssl, now I would like to read the encrypted file (actually parse that file) without decrypting it. 我已经用openssl加密了一个文件,现在我想读取加密的文件(实际上是解析该文件)而不解密。 Basically I want to see if the encrypted file contains a certain word. 基本上我想看看加密文件中是否包含某个单词。 How can I do that? 我怎样才能做到这一点? I searched different blogs and posts and the only solution I could come up with is to decrypt the file (which creates a new READABLE file), search the word in the decrypted file and then remove it. 我搜索了不同的博客和帖子,而我想出的唯一解决方案是解密文件(这将创建一个新的READABLE文件),在解密的文件中搜索单词,然后将其删除。 Since I don't like having to create a decrypted copy of the file and then remove it, is there any way that I can parse/read the file without decrypting it? 由于我不喜欢先创建文件的解密副本然后将其删除,所以有什么方法可以在不解密的情况下解析/读取文件? I should probably mention that I am using c++, but I don't think it really matters, am I correct? 我可能应该提到我正在使用c ++,但我认为这并不重要,对吗? Thanks in advance for all the help you can give me. 预先感谢您可以给我的所有帮助。

There is no way to parse a file that is encrypted (at least if you are using a reasonable, not trivially breakable - pretty much everything beyond a Ceasar cipher or a XOR cipher counts as "not trivially breakable" in this context). 无法解析经过加密的文件(至少,如果您使用的是合理的,不可破解的文件-在这种情况下,除了Ceasar密码或XOR密码以外,几乎所有东西都被视为“不可破解”)。

In other words, you will need to find a way to decrypt the content - one solution is of course to decrypt to memory, or to stdout and use a pipe to read from the file. 换句话说,您将需要找到一种解密内容的方法-一种解决方案当然是解密到内存或stdout并使用管道从文件中读取。

An example (written here as a general idea, the exact code may need some adjusting): 一个示例(此处写为一般性想法,确切的代码可能需要一些调整):

FILE* p = popen("openssl des3 -d -in myfile.encrypted", "r"); 
int ch;
while((ch = fgetc(p)) != EOF)
{
   ... process a character at a time ... 
}
pclose(p);

I have encrypted a file with openssl, now I would like to read the encrypted file (actually parse that file) without decrypting it... to see if the encrypted file contains a certain word. 我已经使用openssl加密了文件,现在我想读取加密的文件(实际上是解析该文件)而不解密它...以查看加密的文件是否包含特定单词。

To preserve semantic security, you need to use a homomorphic encryption scheme. 为了保持语义安全,您需要使用同态加密方案。 OpenSSL does not support those cryptosystems, so its probably not possible using OpenSSL. OpenSSL不支持这些密码系统,因此使用OpenSSL可能无法实现。

If you don't care about semantic security, then you can probably use any number of schemes. 如果您不关心语义安全性,那么可以使用许多方案。 Mats gave you a couple of them. Mats给了你几个。 But they will leak information like a sieve and are probably trivial to break with simple techniques like frequency analysis. 但是它们会像筛子一样泄漏信息,并且可能很难通过频率分析等简单技术来打破。

You might want to read up on Fully Homomorphic Encryption and Somewhat Homomorphic Encryption schemes. 您可能需要阅读“完全同态加密”和“有点同态加密”方案。 If the scheme is built on a lattice, then the NTRU library might offer the scheme or a useful primitive. 如果方案建立在网格上,则NTRU库可能会提供方案或有用的原语。 Shoup's NTL library might also offer the scheme or primitives. Shoup的NTL库也可能提供方案或原语。 (I don't know because I don't use FHE or SHE schemes). (我不知道,因为我不使用FHE或SHE方案)。

You should also talk to the folks on security.stackexchange.com or crypto.stackexchange.com. 您还应该在security.stackexchange.com或crypto.stackexchange.com上与人们交谈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM