Answer the question
In order to leave comments, you need to log in
Is there an analogue of Python's HMAC-SHA1 Signature in Java?
Port the program from python to java (Google Music API). Stuck on signature generation. Python script returns:
import base64
import hmac
from hashlib import sha1
base = "11"
key = "34ee7983-5ee6-4147-aa86-443ea062abf774493d6a-2a15-43fe-aace-e78566927585"
salt = '1386759932759'
mac = hmac.new(key, base, sha1)
mac.update(salt)
sig = base64.urlsafe_b64encode(mac.digest())
print sig;
#nYVoP7wXhJAMGLlY4mcCwfIilMw=
String sig = "";
String salt = "1386759932759";
String base_string = "11";
String key = "34ee7983-5ee6-4147-aa86-443ea062abf774493d6a-2a15-43fe-aace-e78566927585";
try {
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secret = new SecretKeySpec(key.getBytes("UTF-8"), mac.getAlgorithm());
mac.init(secret);
mac.update(salt.getBytes("UTF-8"));
byte[] digest = mac.doFinal(base_string.getBytes());
sig = new String(android.util.Base64.encode(digest, android.util.Base64.URL_SAFE));
} catch (Exception e) {
e.printStackTrace();
}
AQUtility.debug("computeSignature",sig);
//Возвращает: H2in0WNfxSCEz3CHNrMVbqfgXt4=
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question