+1 vote

Hello, please help.
I need to create hash of string, ex.

var gen_sha256(str):
    ...
print(gen_sha256("godot"))

should print:

c629695bba3cbb3a0fb0eab3a7746c72836fecb938073f483627bb144ebbfeb6

HashingContext is not working, says:

Identifier 'HashingContext' is not declared in the current scope.
in Engine by (16 points)

Your error is in whoever is using HashingContext so, can you make a snippet of that part of the code, probably your gen_sha256 method. Also the docs seem pretty clear cut on how to do it.

Error with that:

var ctx = HashingContext.new()

I use extends Node like in docs. Also I have no gen_sha256, just want to create.

I took a deeper look into the docs and it seems that the String class has a sha256_text method that does the hashing for you. So all you would need to do is call it:

func sha_256(str: String) -> String:
    return string.sha256_text()

Yeah! That works, thanks a lot!
How can I upvote you?

I added an actual answer so you can select it.

1 Answer

+4 votes
Best answer

I took a deeper look into the docs and it seems that the String class has a sha256_text method that does the hashing for you. So all you would need to do is call it:

func sha_256(str: String) -> String:
    return string.sha256_text()
by (572 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.