Can I decrypt an encrypted file even if someone has modified it?

Warning: This question has been heavily edited. I tried my best to guess the original intentions of the author. Check out the original version .


I'm not sure how to use the GPG command line tool that we use to encrypt files.

File.txt is a simple text file:

Testing
hello world  
My security things.

This is how I encrypt the file:

gpg --symmetric File.txt 

      

This gives me a new, encrypted file: File.txt.gpg

If someone now modifies the encrypted file, I can no longer decrypt it.

$ gpg --decrypt File.txt.gpg 
gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: eof

      

How can I get the content of my file even if someone has changed it?

+2


a source to share


4 answers


A typical symmetric encryption mode works on blocks of data, and the results of each block are used to encrypt the next block.

A block is usually 128 to 256 bits long. If any bit within the block is corrupted, then the entire block cannot be decrypted. If this were not the case, then it would be possible to get some information about the contents of the block, even without the key. An important part of any good encryption algorithm is that changing one bit in plaintext or cyphertext can change any number of bits in the corresponding cyphertext or plaintext.



Another important feature of the encryption mechanism is that identical blocks in the plaintext are not encrypted into identical blocks in the cyphertext. If they were, then it would be possible to get information about the content of the plaintext. For example, a bitmap image file might be legible when encrypted if each block was encrypted exactly the same, because of the patterns that appear. For this reason, the results of encrypting one block are sometimes used to encrypt the next block. There are also general techniques in which only the key affects the encryption of subsequent blocks and not the plaintext.

If the encryption results of one block affect how the next blocks are encrypted, then incrementing one bit in one block will cause the rest of the cyphertext to follow to make that block unrecoverable.

+4


a source


Answering the original question in layman terms;

If you don't know exactly what changes were made to your encrypted file, your content is gone and you probably won't be able to get it back.



This is why encrypted files are used to protect your data; they really have a hard time working backwards.

+1


a source


You must create and distribute a digest of the encrypted file along with the encrypted file itself.

Before decrypting the file, compute the digest and check if it matches the one provided. If the digests do not match, the encrypted file was corrupted and invalid.

You cannot encrypt a file and then modify it and pretend to be valid encrypted.

0


a source


You cannot do this with just an encrypted file.

I believe you are looking for data redundancy . CD, for example, is. You can scratch one and all the data is still readable, even though a lot of data is lost from scratch.

The easiest way to do this is to simply save the file twice using a checksum that you can tell if one of them has changed. More advanced techniques use interleaved checksums and parity / bytes. An overview of error detection and correction techniques can be found on Wikipedia.

I don't recommend that you implement it yourself. It's much easier and safer to just use an existing implementation. (I'm sure there are some, but I don't know them.)

0


a source







All Articles