Simple question. I have a source file and I have encrypted it with a certain public key. If I take this exact same source file, encrypt it with the exact same key a few hours later would the file hash of the two encrypted files be the same?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
The short answer is NO: you will not obtain identical ciphertexts from the same file encrypted using two different runs of a decent public key file-encryption software; their hash will not coincide.
The longer answer (in theory):
If you use a deterministic public key encryption scheme like textbook RSA, i.e., without randomized padding, then yes.
If you use a secure public key encryption scheme such as RSA OAEP (providing at least IND-CPA security), i.e., encrypting the same message twice with the same public key produces different ciphertexts with overwhelming probability, then no.
However, in the latter case your randomness used for encryption may be computed pseudorandomly from some known value (such as the message itself), as for instance used in message-locked encryption, then the answer turns to yes again.
If you encrypt larger files (larger then the supported message space of the public key encryption scheme) with a public key encryption scheme you should use hybrid encryption. This is also what will be used by a file-encryption software.
Let us denote the public key as $pk$ and the document as $m$.
If you set $k=k'$, i.e., use the same symmetric key, then $c_2=c_2'$ (depending on the mode of operation used for the symmetric cipher you may also require to use the same IV/nonce). Otherwise, if $k\neq k'$ then $c_2\neq c_2'$ with overwhelming probability.
If you use a deterministic public key encryption scheme, then $c_1=c_1'$. If you use a probabilstic (secure) public key encryption scheme, then $c_1\neq c_1'$ with overwhelming probability (as said above, one however can turn probabilistic public key encryption deterministic public key encryption).
Hashing the ciphertext
Now, the first part of the answer only refered to deterministic/probabilistc encryption. It additionally depends on what you see as the hash of the ciphertext, or if you hash the file as it is, and what you want to guarantee in your application and what you want to store.