Let's suppose we have a function hash(T) that is cryptographically secure; a function combine(T,C) that simply concatenates token T with constant C; and a function xor(H1,H2) that performs bitwise exclusive or between H1 and H2 (of same length) and returns result. Is it safe to:
ask user for a token t and plaintext m;
let ha = hash(combine(t,"a")); let hb = hash(combine(t,"b")); let he = xor(hb,m);
then store ha,he on a database (assuming m and hb are of same length)?
to decrypt m, user has to provide token t only; we then:
let ha = hash(combine(t,"a")); let hb = hash(combine(t,"b"));
and select xor(he,:hb) where ha=:ha to retrieve plaintext m.
Is it really that simple, or am I missing something? Or, can an attacker brute-force hb out of ha knowing that inputs differ by "a" and "b" only (assuming hash is SHA-256 or similar)? Then, would it be any safer to use xor(t,X) instead of (or together with) simple string concatenation?
I will really appreciate any suggestions. Thank you!
Andrea