This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
danielsv03's profile picture

SHA256 how to use

Started by danielsv03, 11 June 2017 - 04:02 PM
danielsv03 #1
Posted 11 June 2017 - 06:02 PM
Hi so i wanted to do some password encryption system and i found sha256.. But i don't know how to uses it..
So any help would be useful
I'm looking for
1. how to convert string into hash
2. compair hash and string
3. koner hash to string again.
4. etc

Thanks :)/>
valithor #2
Posted 11 June 2017 - 07:23 PM
Assuming you are using anavrins sha256 api from: https://pastebin.com/6UV4qfNF

One note before I start explaining. sha256 is a hash not encryption, which means it is one way. You can turn a string into a hash, but not a hash back into the original string.

1:

--# load the api using os.loadAPI(filename), where filename is the name of the file
local stringToHash = "hello world"
local hashedString = filename.digest(stringToHash)

2:
You can't compare them directly, instead you hash the string you want to compare to the hash and compare the hashes

local hashedString = digest("hello world")
local stringToCompare = "hello world"
if digest(stringToCompare) == hashedString then
  --# they are equal
end

3: You can't by definition of a hash. A hash cannot be "decrypted" by definition.