This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I want to connect a programm to the OBS Websocket Plugin and need to encrypt the password to match the encryption of the plugin as an authentification. Here is explained how I have to encrypt the password but ony the encryption from this Site worked.

I have to generate a binary SHA256 hash and encode the result to Base64 but this code won't work: Marshalls.utf8_to_base64( str((passwort+salt).sha256_text() ) )

Example Strings with expected output:
1. Data from OBS Websocket: {"authRequired":true,"challenge":"l5BYHeT6ajjiU50aAt97PKzvYJXMVCOwjRn4AWRylXk=","message-id":"auth_request","salt":"Ue+UWGL1GUN4b7SWTcGJ+7b9rjwmWtRVdOIqzt5qfkc=","status":"ok"}
Password: "testtest"
2. password+salt -> binarysha256 -> Base64 encryption
3. result from 2. +challenge -> binary
sha256 -> Base64 encryption

Result from 2. (password+salt): zoa5uikt6WyiwaKU3PMVj+TYao+miy3hyQ6HisYXt20=
Result from 3. (2. + challenge): VXGXqUbOxTwxICHvnObyZv9+2o4OLuXH5qxJ7AupzaY=

The 3rd result is the final and worked but only with the website and not with Godot.

I hope someone can explaine where the mistake in this code is.
Unfortunately i am not familiar with encryption and hashing.

in Engine by (226 points)
edited by

1 Answer

+1 vote
Best answer

I'm not sure, but I believe the problem is that you are using the .sha256_text() function.
This already converts your sha256 binary to a string, but I'm not sure if this is indeed utf8.

Could you try again but with the binary version instead.

var salt = "Ue+UWGL1GUN4b7SWTcGJ+7b9rjwmWtRVdOIqzt5qfkc="
var challenge = "l5BYHeT6ajjiU50aAt97PKzvYJXMVCOwjRn4AWRylXk="
var password = "testtest"

var two = Marshalls.raw_to_base64((password+salt).sha256_buffer())
var three = Marshalls.raw_to_base64((two+challenge).sha256_buffer())
print(two) # zoa5uikt6WyiwaKU3PMVj+TYao+miy3hyQ6HisYXt20=
print(three) # VXGXqUbOxTwxICHvnObyZv9+2o4OLuXH5qxJ7AupzaY=
by (244 points)
selected by

Thank you very much, that solved my problem!

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.