hashing some data and encrypting data share some similar attributes. Surely this is why "Difference between encrypting something and hashing something" has been asked.
The point of this question is hence not repeating the different purposes. Instead I would like to ask.
Since hashing does not, by intention provide a way back I was wondering if there would be a possibility enhance a hashing scheme as to allow a way to revert the data.
To keep this a concrete and less abstract question assume this case.
- Let there be
data
and akey
provided initially (which I agree is already some derivation to hashing in which there is onlydata
) - Then let the key serve as the initial input to a perform a hashing operation. For instance this could be a
SHA256(key)
- Let step 2 be continuously repeated using the result of the previous step as new input. (So essentially this would be a
SHA256(SHA256(key))
as the result of the second round). The results of each round are collected until it reaches the length ofdata
. - Finally let the data be
XOR
'ed with this "hash-generated one-time-pad"
Now to reverse the steps 1 to 3 can also be used to reverse again from the ciphertext to the plaintext data.
In this concrete example it seems that somehow hashing has essentially become encryption. The question therefore is this: Can this be?, is the scheme presented above an encryption scheme mainly consisting of a hashing function?
Addition
would the hash be a cryptographic safe pseudo-random-number-generator (CSPRNG) and hence this hash be part of a stream cipher setup?
Or:
Can a hash become a CSPRNG (and this would be then a stream cipher)?
Update
With happiness I have read all and even accepted one answer with thanks. Yet I want to stress that the questions focus was less "Is this suggested algorithm a safe encryption scheme" (it is not in particular the question of safety), Instead it was about logical connectedness/links between what can be understood as encryption and which is understood as hashing
Given that for instance both hashing and encryption often attempt to produce a pseudo-random deterministic outcome. I think the question hence "can hashing become encryption?" is answered well, as it seems in some respects there is chance to use mainly a hash and end up at least with a weak encryption. Maybe the only think yet still missing (because much of some answer's efforts focus on the safety of the example algorithm) is maybe. (1) If all encryption can be seen as hashing? and be (2) all encryption bases on hashing? (which I do not think)
Yet the question is already answered very nicely so any addition focusing on that aspects (instead of the safety of the algorithm - which was simple to be more concrete) would be nice.