0

I am trying to translate some crypto function from javascript to python, but I don't know what is the equivalent for Hmac function.

I have in javascript:

var crypto = require('crypto');
var myHash = function(seed){
    var hash = crypto.createHmac('sha256', seed).digest('hex');
(...)

And in python It is supposed to be (I guess):

from hashlib import sha256
import hmac
def myHash(seed):
    hash = hmac.new(serverSeed,b"",sha256).hexdigest()

The thing is that in Python hmac function a third parameter is needed: the message. So whe have key, message and algorithm to create the hash. But in the Javascript sample code only Key and algorithm type are set. In the Javascript hmac function message is supposed to be an empty string? What should be the most accurate translation?

1 Answer 1

1

So you are digesting an hmac in JavaScript that has no content? What is the purpose of that?

You usually want to use hmac for message authentication, but if you don't have a message, there isn't really anything to authenticate.

Can you be more specific as why you try to use hmac without content?

Normally in JS you would do something like this:

var crypto = require('crypto');
var myHash = function(seed){
    var hash = crypto.createHmac('sha256', seed).update('my message').digest('hex');
(...)

And that would be pretty much exactly the same thing in Python.

Sign up to request clarification or add additional context in comments.

3 Comments

I am trying to translate to python the CRASH GAME code from csgoroll.com/en/provably/info
I think they just change the seed but never update message, the question It's if it is the same as put empty string like I did in python
I see, in that case, yes, it would be the same as an empty string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.