# Is it ok to store the plaintext hash of encrypted data

Is it ok to create and store the hash (unkeyed hash function) of a plaintext before encryption or does it lead to vulnerabilities? If it is ok are there requirements for the used hash function and encryption algorithm?

Important to mention is that the hash should not be used for integrity checks or something like that.

• What is it used for? What are your security requirements, i.e. why are you using encryption in the first place? Are you planning on storing the digest and the cipher text in the same location or in different locations? – Henrick Hellström Feb 18 '16 at 13:08
• I want to encrypt files and the digest and the cipher text should be stored in the same location. The question is more theoretical but the hash could be used for example for searching or something like this. – Bernhard Feb 18 '16 at 13:20
• Why not hash the encrypted file? – genericUser Feb 18 '16 at 13:49
• I believe this goes against the use case as seen in OP's comment. – Artjom B. Feb 18 '16 at 13:55
• @ArtjomB. you are right. – Bernhard Feb 18 '16 at 14:08

Moreover, since the hash is deterministic, it allows some kinds of inference attacks, because if two stored hashs $h_1$ and $h_2$ are equal, then, they are probably hashs of the same message. This is the reason we use probabilistic encryption schemes.
• Hello, @MaartenBodewes. Well, like which statement? I said "probably" because even if $m_1 \neq m_2$, it may happen that $h(m_1) = h(m_2)$... – Hilder Vitor Lima Pereira Feb 18 '16 at 16:20