.netrestsha1mediafire

MediaFire Rest API session signature SHA1?


I'm trying to connect to MediaFire using their API.

According to the documen the get_session_token request one of the required parameters is:

signature: a SHA1-hashed string that contains the following 4 elements in this sequence: email + password + application_id + API Key. For example, email: testemail@domain.com, password: 111111, application_id: 9999, and API key: abcdefghijklmnopqrst, then signature should be calculated as follows: SHA1('testemail@domain.com1111119999abcdefghijklmnopqrst')

The problem I'm having is with the SHA1, I don't know how to hash the string to the desired SHA1. I'm using .NET (and I tried several ways) but I even tried with python (hashlib.sha1('token').hexdigest()) and it didn't work (tried accessing via Internet browser).

Has anyone experienced this issue before?


Solution

  • This is the sort of pattern I follow when creating string representations of some hashed data:

    string data = "testemail@domain.com1111119999abcdefghijklmnopqrst";
    byte[] bytes = Encoding.UTF8.GetBytes(data);
    byte[] hash;
    
    using (SHA1 sha1 = new SHA1Managed())
        hash = sha1.ComputeHash(bytes);
    
    //You would use hashString for the signature parameter.
    string hashString = BitConverter.ToString(hash).Replace("-", "").ToLower();