I need your help. My java and python scripts not getting the ame sha-1 value of a string:
hash.py
# -*- coding: utf-8 -*-
import hashlib
username = raw_input('username:')
timestamp = raw_input('timestamp:')
app_id = 'dad'
secret_key = 'dadda'
print 'The hashed string is: ' , hashlib.sha1( username + timestamp + app_id + secret_key ).hexdigest()
hash.java
public static String generateSHA1(String password)
{
String sha1 = "";
try
{
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(password.getBytes("UTF-8"));
sha1 = byteToHex(crypt.digest());
}
catch(Exception e)
{
e.printStackTrace();
}
return sha1;
}
private static String byteToHex(final byte[] hash)
{
Formatter formatter = new Formatter();
for (byte b : hash)
{
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
UPDATE: Assuming password is already the concatenated: username, timestamp, app_id and secret_key
Is there something I missed? I think there is something wrong with my java code re. UTF-8 outputting this: \xe2\x80\x8b but I couldn't figure it out. Any help will be appreciated. Thanks.
eeae0d665ed71f3d8f4e3d344fda1c3735dc46c0hashed value for both using your sample inputs.