You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users-cn@cloudstack.apache.org by Du Jun <dj...@gmail.com> on 2013/11/07 08:13:32 UTC

API credential failed

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