Token Creation
Example Java code to generate an IMG Arena API Token would be as follows:
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
public class TokenGenerator {
private static final String SAMPLE_TOKEN = "testtoken";
private static final String UTF_8 = "UTF-8";
private static final String HMAC_MD5 = "HmacMD5";
public static String getToken(String secret, String ip, long timestamp)
throws NoSuchAlgorithmException, InvalidKeyException,
UnsupportedEncodingException {
String keyString = secret + ":" + ip + ":" + timestamp;
SecretKey key = new SecretKeySpec(secret.getBytes(UTF_8), HMAC_MD5);
Mac mac = Mac.getInstance(HMAC_MD5);
mac.init(key);
return Hex.encodeHexString(mac.doFinal(keyString.getBytes(UTF_8)));
}
public static void main(String[] args) throws Exception {
long time = System.currentTimeMillis();
String a = getToken(SAMPLE_TOKEN, "1.2.3.4", time);
System.out.println(a + ":" + time);
}
}Token validity
Stream URL validity
Last updated
Was this helpful?