cloudstack-users-cn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Du Jun <dj199...@gmail.com>
Subject API credential failed
Date Thu, 07 Nov 2013 07:13:32 GMT
Hi,
    I have both apikey and secretkey,and I use the following code to
generate signature:

package test;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;

public class Sign {
public static void main(String args[]) throws Exception{
String
apikey="zr_w86-A-2TsaDzgEUbJZ1PNICWv8L4H_ywHcIwgHX186nAbpHVn4c-FLuAbRjjzVt9r890HE-me_lNDc7yxMw";
String request=("apikey="+apikey+"&command=listZones").toLowerCase();
String
secret="w4ZW_kQeEtmfbLOeBz6Pj39iHUdqlpnfYd62o7bSn3PK7uLElQHE0nCLLRU8i3fu72-vC1JxzmvuEEMxt6WwVQ";
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec keySpec = new
SecretKeySpec(secret.getBytes("UTF-8"),"HmacSHA1");
mac.init(keySpec);
mac.update(request.getBytes());
byte[] encryptedBytes = mac.doFinal();
System.out.println(Base64.encodeBase64String(encryptedBytes)); //result
}
}

I think my signature is correct.Then I generate complete URL:
http://172.17.4.104:8080/client/api?command=listZones&apiKey=zr_w86-A-2TsaDzgEUbJZ1PNICWv8L4H_ywHcIwgHX186nAbpHVn4c-FLuAbRjjzVt9r890HE-me_lNDc7yxMw&signature=jS94Qv63W1h9QGS23zPg3kMIU7o

However,I get the error message as show below:
<listzonesresponse cloud-stack-version="4.0.2.20130501180711">
<errorcode>401</errorcode>
<errortext>unable to verify user credentials</errortext>
</listzonesresponse>

I just don't know why?Any reply will be appreciated!

-----------------------------
Best regards,

Frank

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message