i am converted my string with SHA256 encrypt method with reference SHA256 in swift . now i need to decrypt string back.thanks in advance
-
How did you converted into String? Could you provide your code? – Taras Chernyshenko Jun 13 '18 at 07:27
-
3SHA256 is a *hashing* method, not an encryption. It *cannot* be reversed. – Martin R Jun 13 '18 at 07:29
1 Answers
Seems like you have misunderstood SHA256. SHA256 is a hashing methodology and not a encryption methodology.
A hash function is any function that can be used to map data of arbitrary size to data of a fixed size. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes
Hash functions generates a unique value to each string/data passed to it as parameters and there is no way to get the string/data back from hash values. Hash functions are like one way stream
The only way you can use hash functions is to generate a unique value for each string you have.
Here is one of the use case for SHA256 to help you better understand
For example, if your app has username and password for each user, saving password in DB as plain text is not much appreciated. Rather what we do is generate a hash key and save hash key in DB as password.
whenever user tries to login in future u get the password passed as param to your API generate the SHA for that and compare it with what you have saved in your DB. Because SHA256 generates a unique value for each string/Data passed to it no two passwords can have same hash value. That confirms that user is trying to login with proper credentials.
Hope this gives you idea of how to use SHA256

- 19,999
- 5
- 45
- 78
-
You should not use “text speak” on SO: https://meta.stackoverflow.com/q/345651/1187415. – Martin R Jun 13 '18 at 07:38